Documentation ¶
Index ¶
- type BadgerCache
- func (c *BadgerCache) ExtendTTL(cacheKey string, item []byte) error
- func (c *BadgerCache) Get(cacheKey string) ([]byte, bool, error)
- func (c *BadgerCache) GetConfig() config.CacheGoConfig
- func (c *BadgerCache) GetItemTTL(cacheKey string) (time.Duration, bool, error)
- func (c *BadgerCache) Init() error
- func (c *BadgerCache) Set(cacheKey string, item []byte) error
- type GoCache
- func (c *GoCache) ExtendTTL(cacheKey string, item []byte) error
- func (c *GoCache) Get(cacheKey string) ([]byte, bool, error)
- func (c *GoCache) GetConfig() config.CacheGoConfig
- func (c *GoCache) GetItemTTL(cacheKey string) (time.Duration, bool, error)
- func (c *GoCache) Init() error
- func (c *GoCache) Set(cacheKey string, item []byte) error
- type RedisCache
- func (c *RedisCache) ExtendTTL(cacheKey string, item []byte) error
- func (c *RedisCache) Get(cacheKey string) ([]byte, bool, error)
- func (c *RedisCache) GetConfig() config.CacheGoConfig
- func (c *RedisCache) GetItemTTL(cacheKey string) (time.Duration, bool, error)
- func (c *RedisCache) Init() error
- func (c *RedisCache) Set(cacheKey string, item []byte) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BadgerCache ¶
type BadgerCache struct { Cache *badger.DB Path string Config config.CacheGoConfig }
The BadgerCache type represents a cache with a Badger database, a time-to-live duration, a tracer, a context, and a path. @property Cache - The `Cache` property is a pointer to a `badger.DB` object. `badger.DB` is a key-value store database that provides fast and efficient storage and retrieval of data. It is commonly used for caching purposes in Go applications. @property TTL - TTL stands for "Time to Live" and it represents the duration for which an item in the cache is considered valid before it expires and needs to be refreshed or reloaded. @property Tracer - The Tracer property is a variable of type trace.Tracer. It is used for tracing and monitoring purposes, allowing you to track the execution of your code and identify any performance issues or bottlenecks. @property CTX - CTX is a context.Context object that is used for managing the context of operations performed by the BadgerCache. It allows for cancellation, timeouts, and passing values across API boundaries. @property {string} Path - The `Path` property is a string that represents the file path where the BadgerCache database is stored.
func (*BadgerCache) ExtendTTL ¶
func (c *BadgerCache) ExtendTTL(cacheKey string, item []byte) error
The `ExtendTTL` function is used to extend the time to live (TTL) of an item in the cache. It takes a cache key and an item as input. The function calls the `Set` function to update the item in the cache with a new TTL. This effectively extends the lifespan of the item in the cache.
func (*BadgerCache) Get ¶
func (c *BadgerCache) Get(cacheKey string) ([]byte, bool, error)
The `Get` function is used to retrieve an item from the cache based on a given cache key. It takes a cache key as input and returns three values: the content of the item (as an interface{}), a boolean indicating if the item exists in the cache, and an error if any occurred.
func (*BadgerCache) GetConfig ¶ added in v0.0.2
func (c *BadgerCache) GetConfig() config.CacheGoConfig
func (*BadgerCache) GetItemTTL ¶
The `GetItemTTL` function is used to retrieve the remaining time to live (TTL) of an item in the cache. It takes a cache key as input and returns the remaining TTL duration, a boolean indicating if the item exists in the cache, and an error if any occurred.
func (*BadgerCache) Init ¶
func (c *BadgerCache) Init() error
The `Init` function is used to initialize the BadgerCache. It opens a connection to the Badger database using the provided path and sets the Cache field of the BadgerCache struct to the opened database. If any error occurs during the initialization process, it is returned.
func (*BadgerCache) Set ¶
func (c *BadgerCache) Set(cacheKey string, item []byte) error
The `Set` function is used to store an item in the cache. It takes a cache key and an item as input. The function serializes the item into bytes using JSON encoding and creates a `BadgerItem` struct with the serialized item and a TTL (time to live) value. It then starts a transaction, sets the cache key-value pair in the transaction, and commits the transaction to persist the changes in the cache. If any error occurs during the process, it is returned.
type GoCache ¶
type GoCache struct { Cache *gocache.Cache Config config.CacheGoConfig }
The GoCache type represents a cache with a specified time-to-live duration and optional tracing and context. @property Cache - The `Cache` property is a pointer to an instance of the `gocache.Cache` struct. This struct represents a cache that can be used to store and retrieve data efficiently. @property TTL - TTL stands for "Time to Live". It is a duration that specifies the amount of time for which an item in the cache should be considered valid before it expires and is removed from the cache. @property Tracer - The Tracer property is of type trace.Tracer. It is used for tracing and monitoring the cache operations. @property CTX - CTX is a context.Context object. It is used to carry request-scoped values across API boundaries and between processes. It allows cancellation signals and request-scoped values to propagate across API boundaries and between processes.
func (*GoCache) ExtendTTL ¶
The `ExtendTTL` function is used to extend the time-to-live (TTL) duration of a specific item in the cache. It takes two parameters: `cacheKey`, which is a string representing the key of the item, and `item`, which is the updated value of the item.
func (*GoCache) GetConfig ¶ added in v0.0.2
func (c *GoCache) GetConfig() config.CacheGoConfig
func (*GoCache) GetItemTTL ¶
The `GetItemTTL` function is used to retrieve the remaining time-to-live (TTL) duration for a specific item in the cache. It takes a `cacheKey` parameter, which is a string representing the key of the item.
func (*GoCache) Init ¶
The `Init` function is initializing the cache by creating a new instance of `gocache.Cache` with the specified time-to-live duration (`TTL`). It also starts a new span using the provided tracer and context for tracing and monitoring purposes. Finally, it assigns the newly created cache to the `Cache` property of the `GoCache` struct.
func (*GoCache) Set ¶
The `Set` function is used to store an item in the cache. It takes two parameters: `cacheKey`, which is a string representing the key for the item, and `item`, which is the actual item to be stored in the cache. The function uses the `cacheKey` and `item` parameters to set the value in the cache using the `gocache.Set` method. It also sets the time-to-live (TTL) for the item to the value specified in the `TTL` property of the `GoCache` struct. Finally, it returns an error if any occurred during the operation.
type RedisCache ¶
type RedisCache struct { Cache *redis.Client Address string DB int Config config.CacheGoConfig }
The RedisCache type represents a Redis cache with properties such as the cache client, time-to-live duration, address, database number, tracer, and context. @property Cache - The `Cache` property is a pointer to a Redis client. Redis is an open-source in-memory data structure store that can be used as a cache or a database. The Redis client allows you to interact with a Redis server and perform operations such as storing and retrieving data. @property TTL - TTL stands for "Time to Live" and it represents the duration for which a cache entry will be considered valid before it expires and is automatically removed from the cache. @property {string} Address - The `Address` property is a string that represents the address of the Redis server. It specifies the host and port where the Redis server is running. @property {int} DB - The `DB` property in the `RedisCache` struct represents the database number to be used for the Redis cache. Redis supports multiple databases, and each database is identified by a numeric index. By specifying the `DB` property, you can choose which database to use for storing the cache data. @property Tracer - The Tracer property is of type trace.Tracer. It is used for distributed tracing, which allows you to track and monitor requests as they flow through different services in a distributed system. @property CTX - CTX is a context.Context object that is used for managing the context of the RedisCache operations. It allows for cancellation, timeouts, and passing values across API boundaries.
func (*RedisCache) ExtendTTL ¶
func (c *RedisCache) ExtendTTL(cacheKey string, item []byte) error
The `ExtendTTL` function is a method of the `RedisCache` struct. It is used to extend the time-to-live (TTL) duration of an item in the Redis cache based on the provided cache key.
func (*RedisCache) Get ¶
func (c *RedisCache) Get(cacheKey string) ([]byte, bool, error)
The `Get` function is a method of the `RedisCache` struct. It is used to retrieve an item from the Redis cache based on the provided cache key.
func (*RedisCache) GetConfig ¶ added in v0.0.2
func (c *RedisCache) GetConfig() config.CacheGoConfig
func (*RedisCache) GetItemTTL ¶
The `GetItemTTL` function is a method of the `RedisCache` struct. It is used to retrieve the remaining time-to-live (TTL) duration of an item in the Redis cache based on the provided cache key.
func (*RedisCache) Init ¶
func (c *RedisCache) Init() error
The `Init` function is a method of the `RedisCache` struct. It initializes the Redis cache by creating a new Redis client and setting it to the `Cache` property of the `RedisCache` struct. The Redis client is created with the provided address and database number. The function returns an error if there is any issue initializing the Redis cache.