Documentation ¶
Index ¶
- Variables
- type CacheItem
- type CacheMode
- type Cacher
- func (c *Cacher) Bypass(orig Origin, zoneName, key string, expires int64) (CacheItem, error)
- func (c *Cacher) Close()
- func (c *Cacher) Delete(zoneName, key string)
- func (c *Cacher) Get(zoneName, key string) (item CacheItem, err error)
- func (c *Cacher) PickMode(mode CacheMode) func(Origin, string, string, int64) (CacheItem, error)
- func (c *Cacher) Purge(zoneName string)
- func (c *Cacher) PurgeAll()
- func (c *Cacher) ReadThrough(orig Origin, zoneName, key string, expires int64) (CacheItem, error)
- func (c *Cacher) Refresh(orig Origin, zoneName, key string, expires int64) (CacheItem, error)
- func (c *Cacher) Reload(orig Origin, zoneName, key string, expires int64) (CacheItem, error)
- func (c *Cacher) Set(zoneName, key string, item CacheItem) error
- func (c *Cacher) WriteThrough(orig Origin, zoneName, key string, expires int64) (CacheItem, error)
- type Origin
Constants ¶
This section is empty.
Variables ¶
Functions ¶
This section is empty.
Types ¶
type CacheItem ¶
type CacheItem struct { //The bytes to actually store. Body []byte //The Unix timestamp in seconds for which this item is valid. //When setting the cache item you will probably want to do something like: time.Now().Unix()+123, where 123 is the validity of the item. Expiration int64 }
CacheItem is the definition if a cached item.
type CacheMode ¶
type CacheMode uint8
CacheMode determines which mode of operation should be applied when using the cache.
const ( // ReadThroughMode will read from cache and in the case of a cache miss or expired, WILL NOT WRITE to the cache. ReadThroughMode CacheMode = iota // WriteThroughMode will read from cache and in the case of a cache miss or expired, WILL SET the cache key to origin. WriteThroughMode // RefreshMode will try to get the cached item. If it exists or is expired, it will overwrite it with origin. Otherwise, nothing happens. // This is used to refresh cache items if they already exist in cache. RefreshMode // BypassMode will simply invoke origin and no other Cacher methods. BypassMode // ReloadMode will bypass reading from cache but WILL SET the cache key to origin. // This is used to touch items into cache. ReloadMode )
type Cacher ¶
type Cacher struct {
// contains filtered or unexported fields
}
Cacher manages a persistent cache with many zones. Managing the zones' size is not supported.
func NewCacher ¶
NewCacher creates a new Cacher. It takes in the base path to write the zones to. A variable number of zoneNames may be specified. The names will be the actual filenames on the filesystem. Passing no zoneNames will cause NewCacher to panic.
func (*Cacher) Close ¶
func (c *Cacher) Close()
Close closes all zones' handlers and does not remove any data. This should be invoked prior to shutdown.
func (*Cacher) Get ¶
Get retrieves a CacheItem indexed by zoneName and key, returning the item and the error ErrCacheHit. If the item does not exist, the error returned is ErrCacheMiss. If the item is expired, the error returned is ErrCacheExpired. If some other error occured, it will be returned.
func (*Cacher) PickMode ¶
PickMode returns one of the following functions: ReadThrough, WriteThrough, Refresh, Bypass or Reload depending on the CacheMode passed in. This is just a convenience. We pass it the mode and get the appropriate function that we can immediately invoke. Since all advanced functions have the same signature, changing the mode of operation is as simple as changing the argument to this function.
func (*Cacher) Purge ¶
Purge completely removes a zone file from the filesystem and Cacher will stop referencing it.
func (*Cacher) PurgeAll ¶
func (c *Cacher) PurgeAll()
PurgeAll invokes Purge for all of the Cacher's zones.
func (*Cacher) ReadThrough ¶
ReadThrough reads from cache but does not store result in cache.
func (*Cacher) Refresh ¶
Refresh refreshes the item if it exists. Returns nil if refreshed or ErrCacheMiss if nothing exists to refresh.