MCPcopy Index your code
hub / github.com/devaccuracy/ledgerforge / NewCache

Function NewCache

internal/cache/cache.go:66–79  ·  view source on GitHub ↗

NewCache creates a new instance of RedisCache by establishing a connection to Redis. It fetches the configuration, initializes Redis, and returns a Cache instance. Returns an error if the configuration or Redis initialization fails.

()

Source from the content-addressed store, hash-verified

64// It fetches the configuration, initializes Redis, and returns a Cache instance.
65// Returns an error if the configuration or Redis initialization fails.
66func NewCache() (Cache, error) {
67 // Fetch configuration settings
68 cfg, err := config.Fetch()
69 if err != nil {
70 return nil, err
71 }
72
73 // Initialize Redis cache with the configured Redis DNS and pool settings
74 ca, err := newRedisCache([]string{cfg.Redis.Dns}, cfg.Redis.SkipTLSVerify, cfg.Redis.PoolSize, cfg.Redis.MinIdleConns)
75 if err != nil {
76 return nil, err
77 }
78 return ca, nil
79}
80
81// NewCacheWithClient creates a new RedisCache using an existing Redis client.
82// No error is returned because no I/O occurs — the client is already validated.

Callers 4

TestSetFunction · 0.85
TestGetFunction · 0.85
TestGetNonExistentKeyFunction · 0.85
TestDeleteFunction · 0.85

Calls 2

FetchFunction · 0.92
newRedisCacheFunction · 0.85

Tested by 4

TestSetFunction · 0.68
TestGetFunction · 0.68
TestGetNonExistentKeyFunction · 0.68
TestDeleteFunction · 0.68