Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SizeOfTypeCacheEntry ¶
Return the size (rss) of a type-cache entry for a given key-string.
Types ¶
type StatCache ¶
type StatCache interface { // Insert an entry for the given object record. // // In order to help cope with caching of arbitrarily out of date (i.e. // inconsistent) object listings, entry will not replace any positive entry // with a newer generation number, or with an equivalent generation number // but newer metadata generation number. We have no choice, however, but to // replace negative entries. // // The entry will expire after the supplied time. Insert(m *gcs.MinObject, expiration time.Time) // Set up a negative entry for the given name, indicating that the name // doesn't exist. Overwrite any existing entry for the name, positive or // negative. AddNegativeEntry(name string, expiration time.Time) // Erase the entry for the given object name, if any. Erase(name string) // Return the current entry for the given name, or nil if there is a negative // entry. Return hit == false when there is neither a positive nor a negative // entry, or the entry has expired according to the supplied current time. LookUp(name string, now time.Time) (hit bool, m *gcs.MinObject) }
A cache mapping from name to most recent known record for the object of that name. External synchronization must be provided.
type TypeCache ¶
type TypeCache interface { // Insert inserts the given entry (name -> type) // with the entry-expiration at now+ttl. Insert(now time.Time, name string, it Type) // Erase removes the entry with the given name. Erase(name string) // Get returns the entry with given name, and also // records this entry as latest accessed in the cache. // If now > expiration, then entry is removed from cache, and // UnknownType is returned. // If entry doesn't exist in the cache, then // UnknownType is returned. Get(now time.Time, name string) Type }
TypeCache is a (name -> Type) map. It maintains TTL for each entry for supporting TTL-based expiration. Sample usage:
tc := NewTypeCache(size, ttl) tc.Insert(time.Now(), "file", RegularFileType) tc.Insert(time.Now(), "dir", ExplicitDirType) tc.Get(time.Now(),"file") -> RegularFileType tc.Get(time.Now(),"dir") -> ExplicitDirType tc.Get(time.Now()+ttl+1ns, "file") -> internally tc.Erase("file") -> UnknownType tc.Erase("dir") tc.Get(time.Now(),"dir") -> UnknownType
func NewTypeCache ¶
NewTypeCache creates an LRU-policy-based cache with given parameters. Any entry whose TTL has expired, is removed from the cache on next access (Get). When insertion of next entry would cause size of cache > maxSizeMB, older entries are evicted according to the LRU-policy. If either of TTL or maxSizeMB is zero, nothing is ever cached.
Click to show internal directories.
Click to hide internal directories.