From 5b1afcdb5a5d25953ea134f72186a180000fcfcf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=82=85=E5=B0=8F=E9=BB=91?= Date: Tue, 24 Dec 2013 21:56:48 +0800 Subject: [PATCH] add timeout description for file and memory cache. --- cache/file.go | 3 ++- cache/memory.go | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/cache/file.go b/cache/file.go index 12982e26..a80f3678 100644 --- a/cache/file.go +++ b/cache/file.go @@ -144,12 +144,13 @@ func (this *FileCache) Get(key string) interface{} { // Put value into file cache. // timeout means how long to keep this file, unit of ms. +// if timeout equals FileCacheEmbedExpiry(default is 0), cache this item forever. func (this *FileCache) Put(key string, val interface{}, timeout int64) error { filename := this.getCacheFileName(key) var item FileCacheItem item.Data = val if timeout == FileCacheEmbedExpiry { - item.Expired = time.Now().Unix() + (86400 * 365 * 10) //10年 + item.Expired = time.Now().Unix() + (86400 * 365 * 10) // ten years } else { item.Expired = time.Now().Unix() + timeout } diff --git a/cache/memory.go b/cache/memory.go index 839fed72..e1284b79 100644 --- a/cache/memory.go +++ b/cache/memory.go @@ -26,7 +26,7 @@ type MemoryCache struct { lock sync.RWMutex dur time.Duration items map[string]*MemoryItem - Every int // run an expiration check Every cloc; time + Every int // run an expiration check Every clock time } // NewMemoryCache returns a new MemoryCache. @@ -52,6 +52,7 @@ func (bc *MemoryCache) Get(name string) interface{} { } // Put cache to memory. +// if expired is 0, it will be cleaned by next gc operation ( default gc clock is 1 minute). func (bc *MemoryCache) Put(name string, value interface{}, expired int64) error { bc.lock.Lock() defer bc.lock.Unlock()