Documentation ¶
Overview ¶
Package cache implements a simple in-memory file cache and provides a simple Fetcher wrapper that uses the cache for its Fetch operations.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Fetcher ¶
Fetcher creates an analysis.Fetcher that implements fetches through the cache, and delegates all other operations to f. If cache == nil, f is returned unmodified. The returned value is safe for concurrent use if f is.
func ParseByteSize ¶
ParseByteSize parses a string specifying a possibly-fractional number with units and returns an equivalent value in bytes. Fractions are rounded down. Returns -1 and an error in case of invalid format.
The supported unit labels are:
B * 2^0 bytes K * 2^10 bytes M * 2^20 bytes G * 2^30 bytes T * 2^40 bytes
The labels are case-insensitive ("10g" is the same as "10G")
Examples:
ParseByteSize("25") ==> 25 ParseByteSize("1k") ==> 1024 ParseByteSize("2.5G") ==> 2684354560 ParseByteSize("10.3k") ==> 10547 ParseByteSize("-45xx") ==> -1 [error]
Types ¶
type ByteSize ¶
type ByteSize int
A ByteSize implements the flag.Value interface to allow specifying a cache size on the command line. Legal size values are as parsed by ParseByteSize.
func (*ByteSize) Get ¶
func (b *ByteSize) Get() interface{}
Get implements a method of the flag.Value interface.
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
A Cache implements a limited-size cache of key-value pairs, where keys are strings and values are byte slices. Entries are evicted from the cache using a least-frequently used policy, based on how many times a given key has been fetched with Get. A *Cache is safe for concurrent use.
func (*Cache) Get ¶
Get fetches the specified key from the cache, returning nil if the key is not present. A successful fetch counts as a usage for the purposes of the cache eviction policy.
func (*Cache) Has ¶
Has returns whether the specified key is resident in the cache. This does not affect the usage count of the key for purposes of cache eviction.