5b1afcdb by 傅小黑

add timeout description for file and memory cache.

1 parent 053e7a6a
...@@ -144,12 +144,13 @@ func (this *FileCache) Get(key string) interface{} { ...@@ -144,12 +144,13 @@ func (this *FileCache) Get(key string) interface{} {
144 144
145 // Put value into file cache. 145 // Put value into file cache.
146 // timeout means how long to keep this file, unit of ms. 146 // timeout means how long to keep this file, unit of ms.
147 // if timeout equals FileCacheEmbedExpiry(default is 0), cache this item forever.
147 func (this *FileCache) Put(key string, val interface{}, timeout int64) error { 148 func (this *FileCache) Put(key string, val interface{}, timeout int64) error {
148 filename := this.getCacheFileName(key) 149 filename := this.getCacheFileName(key)
149 var item FileCacheItem 150 var item FileCacheItem
150 item.Data = val 151 item.Data = val
151 if timeout == FileCacheEmbedExpiry { 152 if timeout == FileCacheEmbedExpiry {
152 item.Expired = time.Now().Unix() + (86400 * 365 * 10) //10年 153 item.Expired = time.Now().Unix() + (86400 * 365 * 10) // ten years
153 } else { 154 } else {
154 item.Expired = time.Now().Unix() + timeout 155 item.Expired = time.Now().Unix() + timeout
155 } 156 }
......
...@@ -26,7 +26,7 @@ type MemoryCache struct { ...@@ -26,7 +26,7 @@ type MemoryCache struct {
26 lock sync.RWMutex 26 lock sync.RWMutex
27 dur time.Duration 27 dur time.Duration
28 items map[string]*MemoryItem 28 items map[string]*MemoryItem
29 Every int // run an expiration check Every cloc; time 29 Every int // run an expiration check Every clock time
30 } 30 }
31 31
32 // NewMemoryCache returns a new MemoryCache. 32 // NewMemoryCache returns a new MemoryCache.
...@@ -52,6 +52,7 @@ func (bc *MemoryCache) Get(name string) interface{} { ...@@ -52,6 +52,7 @@ func (bc *MemoryCache) Get(name string) interface{} {
52 } 52 }
53 53
54 // Put cache to memory. 54 // Put cache to memory.
55 // if expired is 0, it will be cleaned by next gc operation ( default gc clock is 1 minute).
55 func (bc *MemoryCache) Put(name string, value interface{}, expired int64) error { 56 func (bc *MemoryCache) Put(name string, value interface{}, expired int64) error {
56 bc.lock.Lock() 57 bc.lock.Lock()
57 defer bc.lock.Unlock() 58 defer bc.lock.Unlock()
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!