github.com/jxskiss/gopkg@v0.17.3/lru/interface.go (about) 1 package lru 2 3 import "time" 4 5 var _ Interface = (*Cache)(nil) 6 var _ Interface = (*ShardedCache)(nil) 7 8 // Interface is an abstract interface of the LRU cache implemented in this package. 9 type Interface interface { 10 11 // Len returns the number of cached values. 12 Len() int 13 14 // Has checks if a key is in the cache and whether it is expired, 15 // without updating its LRU score. 16 Has(key interface{}) (exists, expired bool) 17 18 // Get returns the cached value for the given key and updates its LRU score. 19 // The returned value may be expired, caller can check the returned value 20 // "expired" to check whether the value is expired. 21 Get(key interface{}) (v interface{}, exists, expired bool) 22 23 // GetWithTTL returns the cached value for the given key and updates its 24 // LRU score. The returned value may be expired, caller can check the 25 // returned value "ttl" to check whether the value is expired. 26 GetWithTTL(key interface{}) (v interface{}, exists bool, ttl *time.Duration) 27 28 // GetQuiet returns the cached value for the given key, but don't modify its LRU score. 29 // The returned value may be expired, caller can check the returned value 30 // "expired" to check whether the value is expired. 31 GetQuiet(key interface{}) (v interface{}, exists, expired bool) 32 33 // GetNotStale returns the cached value for the given key. The returned value 34 // is guaranteed not expired. If unexpired value available, its LRU score 35 // will be updated. 36 GetNotStale(key interface{}) (v interface{}, exists bool) 37 38 // MGet returns map of cached values for the given interface keys and 39 // update their LRU scores. The returned values may be expired. 40 // It's a convenient and efficient way to retrieve multiple values. 41 MGet(keys ...interface{}) map[interface{}]interface{} 42 43 // MGetNotStale is similar to MGet, but it returns only not stale values. 44 MGetNotStale(keys ...interface{}) map[interface{}]interface{} 45 46 // MGetInt returns map of cached values for the given int keys and 47 // update their LRU scores. The returned values may be expired. 48 // It's a convenient and efficient way to retrieve multiple values for 49 // int keys. 50 MGetInt(keys ...int) map[int]interface{} 51 52 // MGetIntNotStale is similar to MGetInt, but it returns only not stale values. 53 MGetIntNotStale(keys ...int) map[int]interface{} 54 55 // MGetInt64 returns map of cached values for the given int64 keys and 56 // update their LRU scores. The returned values may be expired. 57 // It's a convenient and efficient way to retrieve multiple values for 58 // int64 keys. 59 MGetInt64(keys ...int64) map[int64]interface{} 60 61 // MGetInt64NotStale is similar to MGetInt64, but it returns only not stale values. 62 MGetInt64NotStale(keys ...int64) map[int64]interface{} 63 64 // MGetUint64 returns map of cached values for the given uint64 keys and 65 // update their LRU scores. The returned values may be expired. 66 // It's a convenient and efficient way to retrieve multiple values for 67 // uint64 keys. 68 MGetUint64(keys ...uint64) map[uint64]interface{} 69 70 // MGetUint64NotStale is similar to MGetUint64, but it returns only not stale values. 71 MGetUint64NotStale(keys ...uint64) map[uint64]interface{} 72 73 // MGetString returns map of cached values for the given string keys and 74 // update their LRU scores. The returned values may be expired. 75 // It's a convenient and efficient way to retrieve multiple values for 76 // string keys. 77 MGetString(keys ...string) map[string]interface{} 78 79 // MGetStringNotStale is similar to MGetString, but it returns only not stale values. 80 MGetStringNotStale(keys ...string) map[string]interface{} 81 82 // Set adds an item to the cache overwriting existing one if it exists. 83 Set(key, value interface{}, ttl time.Duration) 84 85 // MSet adds multiple items to the cache overwriting existing ones. 86 // Unlike calling Set multiple times, it acquires lock only once for 87 // multiple key-value pairs. 88 MSet(kvmap interface{}, ttl time.Duration) 89 90 // Del removes a key from the cache if it exists. 91 Del(key interface{}) 92 93 // MDel removes multiple interface keys from the cache if exists. 94 // It's a convenient and efficient way to remove multiple keys. 95 MDel(keys ...interface{}) 96 97 // MDelInt removes multiple int keys from the cache if exists. 98 // It's a convenient and efficient way to remove multiple int keys. 99 MDelInt(keys ...int) 100 101 // MDelInt64 removes multiple int64 keys from the cache if exists. 102 // It's a convenient and efficient way to remove multiple int64 keys. 103 MDelInt64(keys ...int64) 104 105 // MDelUint64 removes multiple uint64 keys from the cache if exists. 106 // It's a convenient and efficient way to remove multiple uint64 keys. 107 MDelUint64(keys ...uint64) 108 109 // MDelString removes multiple string keys from the cache if exists. 110 // It's a convenient and efficient way to remove multiple string keys. 111 MDelString(keys ...string) 112 }