Documentation ¶
Overview ¶
Package fs provides cache with file system storage
Index ¶
- Constants
- type Cache
- func (c *Cache) Delete(key string) bool
- func (c *Cache) Expired() int
- func (c *Cache) Flush() bool
- func (c *Cache) Get(key string) any
- func (c *Cache) GetExpiration(key string) time.Time
- func (c *Cache) GetWithExpiration(key string) (any, time.Time)
- func (c *Cache) Has(key string) bool
- func (c *Cache) Set(key string, data any, expiration ...cache.Duration) bool
- func (c *Cache) Size() int
- type Config
Examples ¶
Constants ¶
View Source
const MIN_CLEANUP_INTERVAL = cache.SECOND
MIN_CLEANUP_INTERVAL is minimal cleanup interval
View Source
const MIN_EXPIRATION = cache.SECOND
MIN_EXPIRATION is minimal expiration duration
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache is fs cache instance
func New ¶
New creates new cache instance
Example ¶
c, _ := New(Config{ Dir: "/path/to/cache", DefaultExpiration: cache.DAY, CleanupInterval: cache.MINUTE, }) c.Set("test", "ABCD") fmt.Println(c.Get("test"))
Output:
func (*Cache) Delete ¶
Delete removes item from cache
Example ¶
c, _ := New(Config{ Dir: "/path/to/cache", DefaultExpiration: cache.DAY, CleanupInterval: cache.MINUTE, }) c.Set("test", "ABCD") c.Delete("test") fmt.Println(c.Get("test"))
Output:
func (*Cache) Expired ¶
Expired returns number of expired items in cache
Example ¶
c, _ := New(Config{ Dir: "/path/to/cache", DefaultExpiration: cache.DAY, CleanupInterval: cache.MINUTE, }) c.Set("test", "ABCD") fmt.Println(c.Expired())
Output:
func (*Cache) Flush ¶
Flush removes all data from cache
Example ¶
c, _ := New(Config{ Dir: "/path/to/cache", DefaultExpiration: cache.DAY, CleanupInterval: cache.MINUTE, }) c.Set("test", "ABCD") c.Flush() fmt.Println(c.Get("test"))
Output:
func (*Cache) Get ¶
GetWithExpiration returns item from cache
Example ¶
c, _ := New(Config{ Dir: "/path/to/cache", DefaultExpiration: cache.DAY, CleanupInterval: cache.MINUTE, }) c.Set("test", "ABCD") fmt.Println(c.Get("test"))
Output:
func (*Cache) GetExpiration ¶
GetWithExpiration returns item expiration date
func (*Cache) GetWithExpiration ¶
GetWithExpiration returns item from cache and expiration date or nil
Example ¶
c, _ := New(Config{ Dir: "/path/to/cache", DefaultExpiration: cache.DAY, CleanupInterval: cache.MINUTE, }) c.Set("test", "ABCD") item, exp := c.GetWithExpiration("test") fmt.Println(item, exp.String())
Output:
func (*Cache) Has ¶
Has returns true if cache contains data for given key
Example ¶
c, _ := New(Config{ Dir: "/path/to/cache", DefaultExpiration: cache.DAY, CleanupInterval: cache.MINUTE, }) c.Set("test", "ABCD") fmt.Println(c.Has("test"))
Output:
Click to show internal directories.
Click to hide internal directories.