Documentation
¶
Overview ¶
filecache is a simple local file-based cache
Index ¶
- Variables
- func IsCacheMiss(err error) bool
- type Cache
- func (c *Cache[T]) Clear() error
- func (c *Cache[T]) Get(key string) (T, error)
- func (c *Cache[T]) GetOrSet(key string, f func() (T, time.Duration, error)) (T, error)
- func (c *Cache[T]) GetOrSetWithTime(key string, f func() (T, time.Time, error)) (T, error)
- func (c *Cache[T]) Set(key string, val T, dur time.Duration) error
- func (c *Cache[T]) SetWithTime(key string, val T, t time.Time) error
- type Option
Constants ¶
This section is empty.
Variables ¶
View Source
var ( NotFound = errors.New("not found") Expired = errors.New("expired") )
Functions ¶
func IsCacheMiss ¶
IsCacheMiss returns true if the error is NotFound or Expired.
Types ¶
type Cache ¶
type Cache[T any] struct { // contains filtered or unexported fields }
func (*Cache[T]) GetOrSet ¶
GetOrSet is a convenience method that gets the value from the cache if it exists, otherwise it calls the provided function to get the value and sets it in the cache. If the function returns an error, the error is returned and the value is not cached.
func (*Cache[T]) GetOrSetWithTime ¶
GetOrSetWithTime is like GetOrSet but it allows the caller to specify the expiration time of the value.
Click to show internal directories.
Click to hide internal directories.