Skip to content

Commit 119f0d3

Browse files
committed
chore: change chinese comment to english
Signed-off-by: Young Xu <[email protected]>
1 parent 7b9b2c3 commit 119f0d3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1394
-323
lines changed

agcache/cache.go

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,51 @@
1414

1515
package agcache
1616

17-
// CacheInterface 自定义缓存组件接口
17+
// CacheInterface defines the contract for custom cache implementations
1818
type CacheInterface interface {
19+
// Set stores a key-value pair in the cache with an expiration time
20+
// Parameters:
21+
// - key: The unique identifier for the cache entry
22+
// - value: The data to be stored
23+
// - expireSeconds: Time in seconds after which the entry should expire
24+
// Returns:
25+
// - error: Any error that occurred during the operation
1926
Set(key string, value interface{}, expireSeconds int) (err error)
2027

28+
// EntryCount returns the total number of entries in the cache
29+
// Returns:
30+
// - entryCount: The current number of entries stored in the cache
2131
EntryCount() (entryCount int64)
2232

33+
// Get retrieves a value from the cache by its key
34+
// Parameters:
35+
// - key: The unique identifier for the cache entry
36+
// Returns:
37+
// - value: The stored value if found
38+
// - error: Error if the key doesn't exist or any other error occurs
2339
Get(key string) (value interface{}, err error)
2440

41+
// Del removes an entry from the cache by its key
42+
// Parameters:
43+
// - key: The unique identifier of the entry to be deleted
44+
// Returns:
45+
// - affected: True if the key was found and deleted, false otherwise
2546
Del(key string) (affected bool)
2647

48+
// Range iterates over all key/value pairs in the cache
49+
// Parameters:
50+
// - f: The function to be executed for each cache entry
51+
// Return false from f to stop iteration
2752
Range(f func(key, value interface{}) bool)
2853

54+
// Clear removes all entries from the cache
2955
Clear()
3056
}
3157

32-
// CacheFactory 缓存组件工厂接口
58+
// CacheFactory defines the interface for creating cache instances
3359
type CacheFactory interface {
34-
//Create 创建缓存组件
60+
// Create instantiates and returns a new cache implementation
61+
// Returns:
62+
// - CacheInterface: A new instance of a cache implementation
3563
Create() CacheInterface
3664
}

agcache/memory/memory.go

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,41 @@ import (
2222
"github.com/apolloconfig/agollo/v4/agcache"
2323
)
2424

25-
// DefaultCache 默认缓存
25+
// DefaultCache implements a thread-safe in-memory cache using sync.Map
2626
type DefaultCache struct {
27-
defaultCache sync.Map
28-
count int64
27+
defaultCache sync.Map // The underlying thread-safe map for storing cache entries
28+
count int64 // Counter for tracking the number of cache entries
2929
}
3030

31-
// Set 获取缓存
31+
// Set stores a key-value pair in the cache
32+
// Parameters:
33+
// - key: The unique identifier for the cache entry
34+
// - value: The data to be stored
35+
// - expireSeconds: Time in seconds after which the entry should expire (currently not implemented)
36+
//
37+
// Returns:
38+
// - error: Always returns nil as the operation cannot fail
3239
func (d *DefaultCache) Set(key string, value interface{}, expireSeconds int) (err error) {
3340
d.defaultCache.Store(key, value)
3441
atomic.AddInt64(&d.count, int64(1))
3542
return nil
3643
}
3744

38-
// EntryCount 获取实体数量
45+
// EntryCount returns the total number of entries in the cache
46+
// Returns:
47+
// - entryCount: The current number of entries stored in the cache
3948
func (d *DefaultCache) EntryCount() (entryCount int64) {
4049
c := atomic.LoadInt64(&d.count)
4150
return c
4251
}
4352

44-
// Get 获取缓存
53+
// Get retrieves a value from the cache by its key
54+
// Parameters:
55+
// - key: The unique identifier for the cache entry
56+
//
57+
// Returns:
58+
// - value: The stored value if found
59+
// - error: Error if the key doesn't exist in the cache
4560
func (d *DefaultCache) Get(key string) (value interface{}, err error) {
4661
v, ok := d.defaultCache.Load(key)
4762
if !ok {
@@ -50,29 +65,40 @@ func (d *DefaultCache) Get(key string) (value interface{}, err error) {
5065
return v, nil
5166
}
5267

53-
// Range 遍历缓存
68+
// Range iterates over all key/value pairs in the cache
69+
// Parameters:
70+
// - f: The function to be executed for each cache entry
71+
// Return false from f to stop iteration
5472
func (d *DefaultCache) Range(f func(key, value interface{}) bool) {
5573
d.defaultCache.Range(f)
5674
}
5775

58-
// Del 删除缓存
76+
// Del removes an entry from the cache by its key
77+
// Parameters:
78+
// - key: The unique identifier of the entry to be deleted
79+
//
80+
// Returns:
81+
// - affected: Always returns true regardless of whether the key existed
5982
func (d *DefaultCache) Del(key string) (affected bool) {
6083
d.defaultCache.Delete(key)
6184
atomic.AddInt64(&d.count, int64(-1))
6285
return true
6386
}
6487

65-
// Clear 清除所有缓存
88+
// Clear removes all entries from the cache
89+
// This operation reinitializes the underlying sync.Map and resets the counter
6690
func (d *DefaultCache) Clear() {
6791
d.defaultCache = sync.Map{}
6892
atomic.StoreInt64(&d.count, int64(0))
6993
}
7094

71-
// DefaultCacheFactory 构造默认缓存组件工厂类
95+
// DefaultCacheFactory is a factory for creating new instances of DefaultCache
7296
type DefaultCacheFactory struct {
7397
}
7498

75-
// Create 创建默认缓存组件
99+
// Create instantiates and returns a new DefaultCache instance
100+
// Returns:
101+
// - agcache.CacheInterface: A new instance of DefaultCache
76102
func (d *DefaultCacheFactory) Create() agcache.CacheInterface {
77103
return &DefaultCache{}
78104
}

0 commit comments

Comments
 (0)