{"modulePath":"github.com/infinitbyte/framework","version":"v1.1.5","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package ccache\n\nAn LRU cached aimed at high concurrency\n\nAn LRU cached aimed at high concurrency\n\n## Variables\n\n```go\nvar NilTracked = new(nilItem)\n```\n\n## Types\n\n```go\ntype Cache struct {\n\t*Configuration\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc New(config *Configuration) *Cache\n```\nCreate a new cache with the specified configuration See ccache.Configure() for creating a configuration\n\n```go\nfunc (c *Cache) Clear()\n```\nClears the cache\n\n```go\nfunc (c *Cache) Delete(key string) bool\n```\nRemove the item from the cache, return true if the item was present, false otherwise.\n\n```go\nfunc (c *Cache) DeleteFunc(matches func(key string, item *Item) bool) int\n```\nDeletes all items that the matches func evaluates to true.\n\n```go\nfunc (c *Cache) DeletePrefix(prefix string) int\n```\n\n```go\nfunc (c *Cache) Fetch(key string, duration time.Duration, fetch func() (interface{}, error)) (*Item, error)\n```\nAttempts to get the value from the cache and calles fetch on a miss (missing or stale item). If fetch returns an error, no value is cached and the error is returned back to the caller.\n\n```go\nfunc (c *Cache) Get(key string) *Item\n```\nGet an item from the cache. Returns nil if the item wasn't found. This can return an expired item. Use item.Expired() to see if the item is expired and item.TTL() to see how long until the item expires (which will be negative for an already expired item).\n\n```go\nfunc (c *Cache) GetDropped() int\n```\nGets the number of items removed from the cache due to memory pressure since the last time GetDropped was called\n\n```go\nfunc (c *Cache) ItemCount() int\n```\n\n```go\nfunc (c *Cache) Replace(key string, value interface{}) bool\n```\nReplace the value if it exists, does not set if it doesn't. Returns true if the item existed an was replaced, false otherwise. Replace does not reset item's TTL\n\n```go\nfunc (c *Cache) Set(key string, value interface{}, duration time.Duration)\n```\nSet the value in the cache for the specified duration\n\n```go\nfunc (c *Cache) SetMaxSize(size int64)\n```\nSets a new max size. That can result in a GC being run if the new maxium size is smaller than the cached size\n\n```go\nfunc (c *Cache) Stop()\n```\nStops the background worker. Operations performed on the cache after Stop is called are likely to panic\n\n```go\nfunc (c *Cache) TrackingGet(key string) TrackedItem\n```\nUsed when the cache was created with the Track() configuration option. Avoid otherwise\n\n```go\nfunc (c *Cache) TrackingSet(key string, value interface{}, duration time.Duration) TrackedItem\n```\nUsed when the cache was created with the Track() configuration option. Sets the item, and returns a tracked reference to it.\n\n```go\ntype Configuration struct {\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc Configure() *Configuration\n```\nCreates a configuration object with sensible defaults Use this as the start of the fluent configuration: e.g.: ccache.New(ccache.Configure().MaxSize(10000))\n\n```go\nfunc (c *Configuration) Buckets(count uint32) *Configuration\n```\nSubKeys are hashed into % bucket count to provide greater concurrency (every set requires a write lock on the bucket). Must be a power of 2 (1, 2, 4, 8, 16, ...) \\[16]\n\n```go\nfunc (c *Configuration) DeleteBuffer(size uint32) *Configuration\n```\nThe size of the queue for items which should be deleted. If the queue fills up, calls to Delete() will block\n\n```go\nfunc (c *Configuration) GetsPerPromote(count int32) *Configuration\n```\nGive a large cache with a high read / write ratio, it's usually unnecessary to promote an item on every Get. GetsPerPromote specifies the number of Gets a key must have before being promoted \\[3]\n\n```go\nfunc (c *Configuration) ItemsToPrune(count uint32) *Configuration\n```\nThe number of items to prune when memory is low \\[500]\n\n```go\nfunc (c *Configuration) MaxSize(max int64) *Configuration\n```\nThe max size for the cache \\[5000]\n\n```go\nfunc (c *Configuration) OnDelete(callback func(item *Item)) *Configuration\n```\nOnDelete allows setting a callback function to react to ideam deletion. This typically allows to do a cleanup of resources, such as calling a Close() on cached object that require some kind of tear-down.\n\n```go\nfunc (c *Configuration) PromoteBuffer(size uint32) *Configuration\n```\nThe size of the queue for items which should be promoted. If the queue fills up, promotions are skipped \\[1024]\n\n```go\nfunc (c *Configuration) Track() *Configuration\n```\nBy turning tracking on and using the cache's TrackingGet, the cache won't evict items which you haven't called Release() on. It's a simple reference counter.\n\n```go\ntype Item struct {\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc (i *Item) Expired() bool\n```\n\n```go\nfunc (i *Item) Expires() time.Time\n```\n\n```go\nfunc (i *Item) Extend(duration time.Duration)\n```\n\n```go\nfunc (i *Item) Release()\n```\n\n```go\nfunc (i *Item) TTL() time.Duration\n```\n\n```go\nfunc (i *Item) Value() interface{}\n```\n\n```go\ntype LayeredCache struct {\n\t*Configuration\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc Layered(config *Configuration) *LayeredCache\n```\nSee ccache.Configure() for creating a configuration\n\n```go\nfunc (c *LayeredCache) Clear()\n```\nClears the cache\n\n```go\nfunc (c *LayeredCache) Delete(primary, secondary string) bool\n```\nRemove the item from the cache, return true if the item was present, false otherwise.\n\n```go\nfunc (c *LayeredCache) DeleteAll(primary string) bool\n```\nDeletes all items that share the same primary key\n\n```go\nfunc (c *LayeredCache) DeleteFunc(primary string, matches func(key string, item *Item) bool) int\n```\nDeletes all items that share the same primary key and where the matches func evaluates to true.\n\n```go\nfunc (c *LayeredCache) DeletePrefix(primary, prefix string) int\n```\nDeletes all items that share the same primary key and prefix.\n\n```go\nfunc (c *LayeredCache) Fetch(primary, secondary string, duration time.Duration, fetch func() (interface{}, error)) (*Item, error)\n```\nAttempts to get the value from the cache and calles fetch on a miss. If fetch returns an error, no value is cached and the error is returned back to the caller.\n\n```go\nfunc (c *LayeredCache) Get(primary, secondary string) *Item\n```\nGet an item from the cache. Returns nil if the item wasn't found. This can return an expired item. Use item.Expired() to see if the item is expired and item.TTL() to see how long until the item expires (which will be negative for an already expired item).\n\n```go\nfunc (c *LayeredCache) GetDropped() int\n```\nGets the number of items removed from the cache due to memory pressure since the last time GetDropped was called\n\n```go\nfunc (c *LayeredCache) GetOrCreateSecondaryCache(primary string) *SecondaryCache\n```\nGet the secondary cache for a given primary key. This operation will never return nil. In the case where the primary key does not exist, a new, underlying, empty bucket will be created and returned.\n\n```go\nfunc (c *LayeredCache) ItemCount() int\n```\n\n```go\nfunc (c *LayeredCache) Replace(primary, secondary string, value interface{}) bool\n```\nReplace the value if it exists, does not set if it doesn't. Returns true if the item existed an was replaced, false otherwise. Replace does not reset item's TTL nor does it alter its position in the LRU\n\n```go\nfunc (c *LayeredCache) Set(primary, secondary string, value interface{}, duration time.Duration)\n```\nSet the value in the cache for the specified duration\n\n```go\nfunc (c *LayeredCache) SetMaxSize(size int64)\n```\nSets a new max size. That can result in a GC being run if the new maxium size is smaller than the cached size\n\n```go\nfunc (c *LayeredCache) Stop()\n```\n\n```go\nfunc (c *LayeredCache) TrackingGet(primary, secondary string) TrackedItem\n```\nUsed when the cache was created with the Track() configuration option. Avoid otherwise\n\n```go\nfunc (c *LayeredCache) TrackingSet(primary, secondary string, value interface{}, duration time.Duration) TrackedItem\n```\nSet the value in the cache for the specified duration\n\n```go\ntype SecondaryCache struct {\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc (s *SecondaryCache) Delete(secondary string) bool\n```\nDelete a secondary key. The semantics are the same as for LayeredCache.Delete\n\n```go\nfunc (s *SecondaryCache) Fetch(secondary string, duration time.Duration, fetch func() (interface{}, error)) (*Item, error)\n```\nFetch or set a secondary key. The semantics are the same as for LayeredCache.Fetch\n\n```go\nfunc (s *SecondaryCache) Get(secondary string) *Item\n```\nGet the secondary key. The semantics are the same as for LayeredCache.Get\n\n```go\nfunc (s *SecondaryCache) Replace(secondary string, value interface{}) bool\n```\nReplace a secondary key. The semantics are the same as for LayeredCache.Replace\n\n```go\nfunc (s *SecondaryCache) Set(secondary string, value interface{}, duration time.Duration) *Item\n```\nSet the secondary key to a value. The semantics are the same as for LayeredCache.Set\n\n```go\nfunc (c *SecondaryCache) TrackingGet(secondary string) TrackedItem\n```\nTrack a secondary key. The semantics are the same as for LayeredCache.TrackingGet\n\n```go\ntype Sized interface {\n\tSize() int64\n}\n```\n\n```go\ntype TrackedItem interface {\n\tValue() interface{}\n\tRelease()\n\tExpired() bool\n\tTTL() time.Duration\n\tExpires() time.Time\n\tExtend(duration time.Duration)\n}\n```\n\n","path":"github.com/infinitbyte/framework/lib/cache","name":"ccache","synopsis":"An LRU cached aimed at high concurrency","isRedistributable":true}
