MCPcopy Create free account
hub / github.com/MertJSX/folderhost / CreateCache

Function CreateCache

utils/cache/create_cache.go:7–27  ·  view source on GitHub ↗
(cleanupInterval time.Duration, properties CacheProperties)

Source from the content-addressed store, hash-verified

5)
6
7func CreateCache[KeyType comparable, DataType any](cleanupInterval time.Duration, properties CacheProperties) *Cache[KeyType, DataType] {
8 cache := &Cache[KeyType, DataType]{
9 Items: make(map[KeyType]CacheItem[DataType]),
10 }
11
12 cache.Properties = properties
13
14 if properties.SetCacheEvent {
15 cache.SetCacheEvent = make(chan KeyType, 100)
16 }
17 if properties.TimeoutCacheEvent {
18 cache.TimeoutCacheEvent = make(chan CacheEvent[KeyType, DataType], 100)
19 }
20
21 if cleanupInterval > 0 {
22 ticker := time.NewTicker(cleanupInterval)
23 cache.Ticker = ticker
24 go cache.Loop()
25 }
26 return cache
27}

Callers 2

createTestCacheFunction · 0.92
main.goFile · 0.85

Calls 1

LoopMethod · 0.80

Tested by 1

createTestCacheFunction · 0.74