Documentation ¶
Overview ¶
Package cache provides an object cache that uses an adaptive replacement policy described by Mediddo & Modha in "Outperforming LRU with an Adaptive Replacement Cache Algorithm".
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BackingStore ¶
type BackingStore interface { // Get is called by the cache when a requested key is not found in the cache and needs // to be read in from the BackingStore. Get(Key) Value // Put is called by the cache when a dirty entry is flushed and should be committed to // the BackingStore. Put(Key, Value) }
BackingStore defines the interface that the cache expects from the storage medium for which it is acting as a cache.
type C ¶
type C struct {
// contains filtered or unexported fields
}
C represents an object cache.
func New ¶
func New(size int, bs BackingStore) *C
New returns a new, initialized Adaptive Replacement Cache.
func (*C) Flush ¶
func (c *C) Flush()
Flush commits all dirty Entries in the cache to the BackingStore.
func (*C) Get ¶
Get returns the Entry containing the Value for the Key k, fetching it from the BackingStore if necessary. Callers _must_ set the IsDirty field for the returned Entry if they change the Value in the Entry to ensure that the change is propagated to the BackingStore. Callers must also not retain the returned Entry.
func (*C) Put ¶
Put associates the Value v with the Key k and stores it in the cache. It additionally marks the Entry dirty so that the new Value will be propagated to the BackingStore. Callers may wish to use Put when they want to completely replace the Value associated with some Key and want to avoid a potentially expensive lookup for the Key in the BackingStore.
type Entry ¶
type Entry struct { // The value associated with the key for this entry. Value Value // Indicates whether this entry has been modified. Callers must set this field // to true when they modify Value. The cache will only commit this Entry to the BackingStore // if IsDirty is true. IsDirty bool // contains filtered or unexported fields }
Entry represents a single entry in the cache.