New release.

Includes the panic when cache is completely disabled.
This commit is contained in:
2024-08-19 15:43:42 +01:00
parent dc9e0906fd
commit ae9a44033b
2 changed files with 28 additions and 0 deletions
+27
View File
@@ -77,6 +77,9 @@ func EnableCache(cfg *CacheConfig) {
func CacheLookup(hash string) []byte { func CacheLookup(hash string) []byte {
if !IsCacheInitialized() { if !IsCacheInitialized() {
config.Logger.Debug(&libpack_logger.LogMessage{
Message: "Cache not initialized",
})
return nil return nil
} }
@@ -112,6 +115,12 @@ func CacheLookup(hash string) []byte {
} }
func CacheDelete(hash string) { func CacheDelete(hash string) {
if !IsCacheInitialized() {
config.Logger.Debug(&libpack_logger.LogMessage{
Message: "Cache not initialized",
})
return
}
config.Logger.Debug(&libpack_logger.LogMessage{ config.Logger.Debug(&libpack_logger.LogMessage{
Message: "Deleting data from cache", Message: "Deleting data from cache",
Pairs: map[string]interface{}{"hash": hash}, Pairs: map[string]interface{}{"hash": hash},
@@ -121,6 +130,12 @@ func CacheDelete(hash string) {
} }
func CacheStore(hash string, data []byte) { 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{ config.Logger.Debug(&libpack_logger.LogMessage{
Message: "Storing data in cache", Message: "Storing data in cache",
Pairs: map[string]interface{}{"hash": hash}, 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) { 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{ config.Logger.Debug(&libpack_logger.LogMessage{
Message: "Storing data in cache with TTL", Message: "Storing data in cache with TTL",
Pairs: map[string]interface{}{"hash": hash, "ttl": 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 { func CacheGetQueries() int64 {
if !IsCacheInitialized() {
config.Logger.Debug(&libpack_logger.LogMessage{
Message: "Cache not initialized",
})
return 0
}
config.Logger.Debug(&libpack_logger.LogMessage{ config.Logger.Debug(&libpack_logger.LogMessage{
Message: "Counting cache queries", Message: "Counting cache queries",
}) })
+1
View File
@@ -57,6 +57,7 @@ func parseConfig() {
c.Cache.CacheRedisURL = getDetailsFromEnv("CACHE_REDIS_URL", "localhost:6379") c.Cache.CacheRedisURL = getDetailsFromEnv("CACHE_REDIS_URL", "localhost:6379")
c.Cache.CacheRedisPassword = getDetailsFromEnv("CACHE_REDIS_PASSWORD", "") c.Cache.CacheRedisPassword = getDetailsFromEnv("CACHE_REDIS_PASSWORD", "")
c.Cache.CacheRedisDB = getDetailsFromEnv("CACHE_REDIS_DB", 0) c.Cache.CacheRedisDB = getDetailsFromEnv("CACHE_REDIS_DB", 0)
/* security */
c.Security.BlockIntrospection = getDetailsFromEnv("BLOCK_SCHEMA_INTROSPECTION", false) c.Security.BlockIntrospection = getDetailsFromEnv("BLOCK_SCHEMA_INTROSPECTION", false)
c.Security.IntrospectionAllowed = func() []string { c.Security.IntrospectionAllowed = func() []string {
urls := getDetailsFromEnv("ALLOWED_INTROSPECTION", "") urls := getDetailsFromEnv("ALLOWED_INTROSPECTION", "")