Get now returns the *Item rather than the item's value. Get no longer actively

purges stale items.

Combining these two changes, CCache can now be used to implement both of
Varnish's grace and saint mode.
This commit is contained in:
Karl Seguin
2014-10-25 17:15:47 +07:00
parent 3a00ce8f0a
commit 77765a3f11
7 changed files with 124 additions and 66 deletions

View File

@@ -35,32 +35,24 @@ func Layered(config *Configuration) *LayeredCache {
return c
}
func (c *LayeredCache) Get(primary, secondary string) interface{} {
if item := c.get(primary, secondary); item != nil {
return item.value
}
return nil
}
func (c *LayeredCache) TrackingGet(primary, secondary string) TrackedItem {
item := c.get(primary, secondary)
if item == nil {
return NilTracked
}
item.track()
return item
}
func (c *LayeredCache) get(primary, secondary string) *Item {
func (c *LayeredCache) Get(primary, secondary string) *Item {
bucket := c.bucket(primary)
item := bucket.get(primary, secondary)
if item == nil {
return nil
}
if item.expires < time.Now().Unix() {
return nil
if item.expires > time.Now().Unix() {
c.conditionalPromote(item)
}
c.conditionalPromote(item)
return item
}
func (c *LayeredCache) TrackingGet(primary, secondary string) TrackedItem {
item := c.Get(primary, secondary)
if item == nil {
return NilTracked
}
item.track()
return item
}