Documentation
¶
Index ¶
- Variables
- type DefaultTimedCache
- func (d *DefaultTimedCache) Delete(key string)
- func (d *DefaultTimedCache) Get(key string) (interface{}, bool)
- func (d *DefaultTimedCache) GetExpirationTime(key string) time.Time
- func (d *DefaultTimedCache) Has(key string) bool
- func (d *DefaultTimedCache) Set(key string, value interface{}) error
- func (d *DefaultTimedCache) UpdateExpirationTime(key string, expiresAt time.Time) error
- func (d *DefaultTimedCache) UpdateExpiresAt(key string, expiresAt time.Time) error
- func (d *DefaultTimedCache) UpdateValue(key string, value interface{}) error
- type TimedCache
- type TimedItem
Constants ¶
This section is empty.
Variables ¶
var ( ErrItemHasExpired = errors.New("item has expired") ErrValueMustBeATimedItem = errors.New("value must be a TimedItem") )
Functions ¶
This section is empty.
Types ¶
type DefaultTimedCache ¶ added in v0.1.5
type DefaultTimedCache struct {
// contains filtered or unexported fields
}
DefaultTimedCache represents an in-memory cache
func NewDefaultTimedCache ¶ added in v0.1.5
func NewDefaultTimedCache() *DefaultTimedCache
NewDefaultTimedCache creates a new DefaultTimedCache instance
func (*DefaultTimedCache) Delete ¶ added in v0.1.5
func (d *DefaultTimedCache) Delete(key string)
Delete removes a value from the cache
Parameters:
- key: The key to remove from the cache
func (*DefaultTimedCache) Get ¶ added in v0.1.5
func (d *DefaultTimedCache) Get(key string) (interface{}, bool)
Get retrieves a value from the cache
Parameters:
- key: The key to retrieve from the cache
Returns:
- interface{}: The cached value, or nil if not found or expired
- bool: True if the value was found and not expired, false otherwise
func (*DefaultTimedCache) GetExpirationTime ¶ added in v0.1.5
func (d *DefaultTimedCache) GetExpirationTime(key string) time.Time
GetExpirationTime retrieves the expiration time of a cached item
Parameters:
- key: The key associated with the cached value
Returns:
- time.Time: The expiration time of the cached item, or zero time if not found
func (*DefaultTimedCache) Has ¶ added in v0.1.5
func (d *DefaultTimedCache) Has(key string) bool
Has checks if the cache contains a key
Parameters:
- key: The key to check in the cache
Returns:
- bool: True if the key exists in the cache and has not expired, false otherwise
func (*DefaultTimedCache) Set ¶ added in v0.1.5
func (d *DefaultTimedCache) Set(key string, value interface{}) error
Set adds the item to the cache
Parameters:
- key: The key to associate with the cached value
- value: The item to be cached
Returns:
- error: An error if the item is nil or has expired
func (*DefaultTimedCache) UpdateExpirationTime ¶ added in v0.1.5
func (d *DefaultTimedCache) UpdateExpirationTime( key string, expiresAt time.Time, ) error
UpdateExpirationTime updates the expiration time of a cached item
Parameters:
- key: The key associated with the cached value
- expiresAt: The new expiration time to be set
Returns:
- error: An error if the item is not found
func (*DefaultTimedCache) UpdateExpiresAt ¶ added in v0.1.5
func (d *DefaultTimedCache) UpdateExpiresAt( key string, expiresAt time.Time, ) error
UpdateExpiresAt updates the expiration time of an item in the cache
Parameters:
- key: The key associated with the cached value
- expiresAt: The new expiration time to be set
Returns:
- error: An error if the item is not found
func (*DefaultTimedCache) UpdateValue ¶ added in v0.1.5
func (d *DefaultTimedCache) UpdateValue(key string, value interface{}) error
UpdateValue updates the value of an item in the cache
Parameters:
- key: The key associated with the cached value
- value: The new value to be set
Returns:
- error: An error if the item is not found
type TimedCache ¶ added in v0.1.4
type TimedCache interface {
gocache.Cache
GetExpirationTime(key string) time.Time
UpdateExpirationTime(key string, expirationTime time.Time) error
}
TimedCache is the interface for timed cache implementations
type TimedItem ¶ added in v0.1.5
type TimedItem struct {
// contains filtered or unexported fields
}
TimedItem represents a cached value with an expiration time
func NewTimedItem ¶ added in v0.1.5
NewTimedItem creates a new cache item
Parameters:
- value: The value to be cached
- expiresAt: The expiration time of the cached value
Returns:
- *TimedItem: A pointer to the newly created cache item
func (*TimedItem) GetExpiresAt ¶ added in v0.1.5
GetExpiresAt returns the expiration time of the cached value
Returns:
- time.Time: The expiration time of the cached value
func (*TimedItem) GetValue ¶ added in v0.1.5
func (i *TimedItem) GetValue() interface{}
GetValue returns the cached value
Returns:
- interface{}: The cached value
func (*TimedItem) HasExpired ¶ added in v0.1.5
HasExpired returns true if the cached value has expired
Returns:
- bool: True if the cached value has expired, false otherwise
func (*TimedItem) SetExpiresAt ¶ added in v0.1.5
SetExpiresAt sets the expiration time of the cached value
Parameters:
- expiresAt: The expiration time to be set