-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathexists.go
28 lines (26 loc) · 868 Bytes
/
exists.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package hermes
// Exists is a method of the Cache struct that checks if a key exists in the cache.
// This method is thread-safe.
//
// Parameters:
// - key: A string representing the key to check for existence in the cache.
//
// Returns:
// - A boolean value indicating whether the key exists in the cache or not.
func (c *Cache) Exists(key string) bool {
c.mutex.RLock()
defer c.mutex.RUnlock()
return c.exists(key)
}
// exists is a method of the Cache struct that checks if a key exists in the cache.
// This method is not thread-safe and should only be called from an exported function.
//
// Parameters:
// - key: A string representing the key to check for existence in the cache.
//
// Returns:
// - A boolean value indicating whether the key exists in the cache or not.
func (c *Cache) exists(key string) bool {
_, ok := c.data[key]
return ok
}