From f98db6d21cda8e00ebd79055ed0c27829b4579da Mon Sep 17 00:00:00 2001 From: John Date: Mon, 10 Jun 2019 21:23:49 +0800 Subject: [PATCH] comments for gcache update --- g/os/gcache/gcache.go | 4 ++-- g/os/gcache/gcache_cache.go | 9 +++------ 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/g/os/gcache/gcache.go b/g/os/gcache/gcache.go index f24ccf268..3cb14481c 100644 --- a/g/os/gcache/gcache.go +++ b/g/os/gcache/gcache.go @@ -7,10 +7,10 @@ // Package gcache provides high performance and concurrent-safe in-memory cache for process. package gcache -// 全局缓存管理对象 +// Default cache object. var cache = New() -// (使用全局KV缓存对象)设置kv缓存键值对,过期时间单位为**毫秒** +// Set sets with , which is expired after milliseconds. func Set(key interface{}, value interface{}, expire int) { cache.Set(key, value, expire) } diff --git a/g/os/gcache/gcache_cache.go b/g/os/gcache/gcache_cache.go index 33ad10e74..e4456a9db 100644 --- a/g/os/gcache/gcache_cache.go +++ b/g/os/gcache/gcache_cache.go @@ -13,13 +13,12 @@ import ( "unsafe" ) -// 缓存对象。 -// 底层只有一个缓存对象,如果需要提高并发性能,可新增缓存对象无锁哈希表,用键名做固定分区。 +// Cache struct. type Cache struct { *memCache } -// Cache对象按照缓存键名首字母做了分组 +// New creates and returns a new cache object. func New(lruCap...int) *Cache { c := &Cache { memCache : newMemCache(lruCap...), @@ -28,10 +27,8 @@ func New(lruCap...int) *Cache { return c } -// 清空缓存中的所有数据 +// Clear clears all data of the cache. func (c *Cache) Clear() { - // 使用原子操作替换缓存对象 old := atomic.SwapPointer((*unsafe.Pointer)(unsafe.Pointer(&c.memCache)), unsafe.Pointer(newMemCache())) - // 关闭旧的缓存对象 (*memCache)(old).Close() } \ No newline at end of file