InitSubsiteCache initializes the Olric cache for subsites
(client *olric.EmbeddedClient)
| 284 | |
| 285 | // InitSubsiteCache initializes the Olric cache for subsites |
| 286 | func InitSubsiteCache(client *olric.EmbeddedClient) error { |
| 287 | subsiteCacheMutex.Lock() |
| 288 | defer subsiteCacheMutex.Unlock() |
| 289 | |
| 290 | if subsiteCacheInitialized { |
| 291 | return nil |
| 292 | } |
| 293 | |
| 294 | if client == nil { |
| 295 | return fmt.Errorf("olric client is nil") |
| 296 | } |
| 297 | |
| 298 | olricClient = client |
| 299 | var err error |
| 300 | SubsiteCache, err = client.NewDMap(CacheConfig.Namespace) |
| 301 | if err != nil { |
| 302 | return fmt.Errorf("failed to create Olric DMap for subsite cache: %v", err) |
| 303 | } |
| 304 | |
| 305 | // Start periodic metrics logging |
| 306 | go logCacheMetricsPeriodically() |
| 307 | |
| 308 | log.Infof("Subsite cache initialized with max entry size: %d KB", CacheConfig.MaxEntrySize/1024) |
| 309 | subsiteCacheInitialized = true |
| 310 | return nil |
| 311 | } |
| 312 | |
| 313 | // addToCache adds an entry to the cache with TTL |
| 314 | func addToCache(cacheKey string, entry *SubsiteCacheEntry) error { |
no test coverage detected