-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathclean.go
70 lines (62 loc) · 1.7 KB
/
clean.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package hermes
import "errors"
// Clean is a method of the Cache struct that clears the cache contents.
// If the full-text index is initialized, it is also cleared.
// This method is thread-safe.
//
// Parameters:
// - None
//
// Returns:
// - None
func (c *Cache) Clean() {
c.mutex.Lock()
defer c.mutex.Unlock()
c.clean()
}
// clean is a method of the Cache struct that clears the cache contents.
// If the full-text index is initialized, it is also cleared.
// This method is not thread-safe and should only be called from an exported function.
//
// Parameters:
// - None
//
// Returns:
// - None
func (c *Cache) clean() {
if c.ft != nil {
c.ft.clean()
}
c.data = map[string]map[string]any{}
}
// FTClean is a method of the Cache struct that clears the full-text cache contents.
// If the full-text index is not initialized, this method returns an error.
// Otherwise, the full-text index storage and indices are cleared, and this method returns nil.
// This method is thread-safe.
//
// Returns:
// - error: An error object. If no error occurs, this will be nil.
func (c *Cache) FTClean() error {
c.mutex.Lock()
defer c.mutex.Unlock()
// Verify that the full text is initialized
if c.ft == nil {
return errors.New("full text is not initialized")
}
// Clean the ft cache
c.ft.clean()
// Return no error
return nil
}
// clean is a method of the FullText struct that clears the full-text index storage and indices.
// This method initializes a new empty storage map and indices map with the maximum length specified in the FullText struct.
//
// Parameters:
// - None
//
// Returns:
// - None
func (ft *FullText) clean() {
ft.storage = make(map[string]any)
ft.indices = make(map[int]string)
}