fixed an issue where disabling the "RamCache" config would cause a crash
Some checks failed
Run Integration Tests / test (push) Failing after 40s

This commit is contained in:
partisan 2025-02-21 21:27:53 +01:00
parent 41c3b7005a
commit ab707a91e8
2 changed files with 41 additions and 16 deletions

View file

@ -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()

View file

@ -30,25 +30,25 @@ type MetaSearchConfig struct {
}
type Config struct {
Port int // Added
AuthCode string // Added
PeerID string // Added
Port int
AuthCode string
PeerID string
Peers []string
Domain string // Added
NodesEnabled bool // Added
MetaSearchEnabled bool // Added
IndexerEnabled bool // Added
WebsiteEnabled bool // Added
Domain string
NodesEnabled bool
MetaSearchEnabled bool
IndexerEnabled bool
WebsiteEnabled bool
RamCacheEnabled bool
DriveCacheEnabled bool // Added
MetaProxyEnabled bool // Added
MetaProxyStrict bool // Added
MetaProxies []string // Added
CrawlerProxyEnabled bool // Added
CrawlerProxyStrict bool // Added
CrawlerProxies []string // Added
DriveCacheEnabled bool
MetaProxyEnabled bool
MetaProxyStrict bool
MetaProxies []string
CrawlerProxyEnabled bool
CrawlerProxyStrict bool
CrawlerProxies []string
// Maybye add Proxy support for Image Extraction?
LogLevel int // Added
LogLevel int
ConcurrentStandardCrawlers int
ConcurrentChromeCrawlers int
CrawlingInterval time.Duration // Refres crawled results in...