fixed an issue where disabling the "RamCache" config would cause a crash
Some checks failed
Run Integration Tests / test (push) Failing after 40s
Some checks failed
Run Integration Tests / test (push) Failing after 40s
This commit is contained in:
parent
41c3b7005a
commit
ab707a91e8
2 changed files with 41 additions and 16 deletions
25
cache.go
25
cache.go
|
@ -123,6 +123,11 @@ func NewGeocodeCache() *GeocodeCache {
|
|||
|
||||
// Get retrieves the results for a given key from the cache.
|
||||
func (rc *ResultsCache) Get(key CacheKey) ([]SearchResult, bool) {
|
||||
// Skip if RAM caching is disabled
|
||||
if !config.RamCacheEnabled {
|
||||
return nil, false
|
||||
}
|
||||
|
||||
rc.mu.Lock()
|
||||
defer rc.mu.Unlock()
|
||||
|
||||
|
@ -143,6 +148,11 @@ func (rc *ResultsCache) Get(key CacheKey) ([]SearchResult, bool) {
|
|||
|
||||
// Set stores the results for a given key in the cache.
|
||||
func (rc *ResultsCache) Set(key CacheKey, results []SearchResult) {
|
||||
// Skip if RAM caching is disabled
|
||||
if !config.RamCacheEnabled {
|
||||
return
|
||||
}
|
||||
|
||||
rc.mu.Lock()
|
||||
defer rc.mu.Unlock()
|
||||
|
||||
|
@ -162,6 +172,11 @@ func (rc *ResultsCache) keyToString(key CacheKey) string {
|
|||
|
||||
// checkAndCleanCache removes items if memory usage exceeds the limit.
|
||||
func (rc *ResultsCache) checkAndCleanCache() {
|
||||
// Skip if RAM caching is disabled
|
||||
if !config.RamCacheEnabled {
|
||||
return
|
||||
}
|
||||
|
||||
if rc.currentMemoryUsage() > config.RamCache.MaxUsageBytes {
|
||||
rc.cleanOldestItems()
|
||||
}
|
||||
|
@ -179,6 +194,11 @@ func (rc *ResultsCache) currentMemoryUsage() uint64 {
|
|||
|
||||
// Get retrieves the geocoding result for a given query from the cache.
|
||||
func (gc *GeocodeCache) Get(query string) (latitude, longitude string, found bool, exists bool) {
|
||||
// Skip if RAM caching is disabled
|
||||
if !config.RamCacheEnabled {
|
||||
return "", "", false, false
|
||||
}
|
||||
|
||||
gc.mu.Lock()
|
||||
defer gc.mu.Unlock()
|
||||
|
||||
|
@ -198,6 +218,11 @@ func (gc *GeocodeCache) Get(query string) (latitude, longitude string, found boo
|
|||
}
|
||||
|
||||
func (gc *GeocodeCache) Set(query, latitude, longitude string, found bool) {
|
||||
// Skip if RAM caching is disabled
|
||||
if !config.RamCacheEnabled {
|
||||
return
|
||||
}
|
||||
|
||||
gc.mu.Lock()
|
||||
defer gc.mu.Unlock()
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue