diff --git a/cache/cache.go b/cache/cache.go index 48274b1..5b0ad94 100644 --- a/cache/cache.go +++ b/cache/cache.go @@ -77,6 +77,9 @@ func EnableCache(cfg *CacheConfig) { func CacheLookup(hash string) []byte { if !IsCacheInitialized() { + config.Logger.Debug(&libpack_logger.LogMessage{ + Message: "Cache not initialized", + }) return nil } @@ -112,6 +115,12 @@ func CacheLookup(hash string) []byte { } func CacheDelete(hash string) { + if !IsCacheInitialized() { + config.Logger.Debug(&libpack_logger.LogMessage{ + Message: "Cache not initialized", + }) + return + } config.Logger.Debug(&libpack_logger.LogMessage{ Message: "Deleting data from cache", Pairs: map[string]interface{}{"hash": hash}, @@ -121,6 +130,12 @@ func CacheDelete(hash string) { } func CacheStore(hash string, data []byte) { + if !IsCacheInitialized() { + config.Logger.Debug(&libpack_logger.LogMessage{ + Message: "Cache not initialized", + }) + return + } config.Logger.Debug(&libpack_logger.LogMessage{ Message: "Storing data in cache", Pairs: map[string]interface{}{"hash": hash}, @@ -130,6 +145,12 @@ func CacheStore(hash string, data []byte) { } func CacheStoreWithTTL(hash string, data []byte, ttl time.Duration) { + if !IsCacheInitialized() { + config.Logger.Debug(&libpack_logger.LogMessage{ + Message: "Cache not initialized", + }) + return + } config.Logger.Debug(&libpack_logger.LogMessage{ Message: "Storing data in cache with TTL", Pairs: map[string]interface{}{"hash": hash, "ttl": ttl}, @@ -139,6 +160,12 @@ func CacheStoreWithTTL(hash string, data []byte, ttl time.Duration) { } func CacheGetQueries() int64 { + if !IsCacheInitialized() { + config.Logger.Debug(&libpack_logger.LogMessage{ + Message: "Cache not initialized", + }) + return 0 + } config.Logger.Debug(&libpack_logger.LogMessage{ Message: "Counting cache queries", }) diff --git a/main.go b/main.go index 5cd6958..3b12218 100644 --- a/main.go +++ b/main.go @@ -57,6 +57,7 @@ func parseConfig() { c.Cache.CacheRedisURL = getDetailsFromEnv("CACHE_REDIS_URL", "localhost:6379") c.Cache.CacheRedisPassword = getDetailsFromEnv("CACHE_REDIS_PASSWORD", "") c.Cache.CacheRedisDB = getDetailsFromEnv("CACHE_REDIS_DB", 0) + /* security */ c.Security.BlockIntrospection = getDetailsFromEnv("BLOCK_SCHEMA_INTROSPECTION", false) c.Security.IntrospectionAllowed = func() []string { urls := getDetailsFromEnv("ALLOWED_INTROSPECTION", "")