Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

mgnsk/weakcache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Weak cache

Weak cache implementation in go. It tracks the reference count of all cached records and evicts one when all references to it have been unreachable for a specified duration of time. A "reference" is simply a unique pointer to the record value which is returned to the caller.

Before returning the pointer, the reference count for the record is increased. Each unique pointer has a finalizer that will decrease the record's reference count. When all pointers to the record have been collected (no references), the record will be evicted.

The eviction delay can be controlled with minTTL. It specifies a grace period during which the record will not be evicted even if it has no references. maxTTL specifies the maximum age of a record.