Documentation ¶
Overview ¶
Package cachelog is a log structured cache. See the README for details.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
func Open ¶
Open a new cache, possibly reading in old data from disk. Passing a nil Config uses the default config.
func (*Cache) Delete ¶
Delete data from the cache. The deletion marker is synced to a separate log file, which guarantees the old data is never served again - even in the face of machine crashes.
func (*Cache) GarbageCollection ¶
func (c *Cache) GarbageCollection()
GarbageCollection runs the garbage collection if needed. If the MaxGarbageRatio isn't violated, GarbageCollection does nothing. The garbage collection process involves copying the still relevant data from the oldest log files to the active log file, this then allows us to remove the old log file and all the stale data with it. Multiple files might be collected in one run, but the active write log file is never considered even if it contains dead data.
type Config ¶
type Config struct { // Expiry controls how long a block should not be read/written before it is discarded during garbage collection. The expiry is a minimum, the block will remain available until it is actually garbage collected. // The default Expiry is 1 week. Expiry time.Duration // LogFileSize controls how large to make each log file. The default is 10MB. Files might be slightly larger. LogFileSize int // MaxGarbageRatio is a number between 0 and 1 that indicates the threshold at which to start garbage collection. // Don't set this too low to avoid excessive IOPS. // The default is 0.75, which starts garbage collection once 75% of the data is dead. MaxGarbageRatio float64 }