Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions modules/cache/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,21 @@ toolchain go1.24.3

require (
github.com/GoCodeAlone/modular v1.3.0
github.com/alicebob/miniredis/v2 v2.35.0
github.com/redis/go-redis/v9 v9.10.0
github.com/stretchr/testify v1.10.0
)

require (
github.com/BurntSushi/toml v1.5.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/golobby/cast v1.3.3 // indirect
github.com/golobby/config/v3 v3.4.2 // indirect
github.com/golobby/dotenv v1.3.2 // indirect
github.com/golobby/env/v2 v2.2.4 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/yuin/gopher-lua v1.1.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
14 changes: 14 additions & 0 deletions modules/cache/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,21 @@ github.com/BurntSushi/toml v1.5.0 h1:W5quZX/G/csjUnuI8SUYlsHs9M38FC7znL0lIO+DvMg
github.com/BurntSushi/toml v1.5.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
github.com/GoCodeAlone/modular v1.3.0 h1:KVny0S447hTUXYY8Y7BltL94poN/ZtaH3v2V7jU7d3o=
github.com/GoCodeAlone/modular v1.3.0/go.mod h1:dD1xYmBQdtYahsrdwP1DAe2Tz6SkCXA8foairMuY3Pk=
github.com/alicebob/miniredis/v2 v2.35.0 h1:QwLphYqCEAo1eu1TqPRN2jgVMPBweeQcR21jeqDCONI=
github.com/alicebob/miniredis/v2 v2.35.0/go.mod h1:TcL7YfarKPGDAthEtl5NBeHZfeUQj6OXMm/+iu5cLMM=
github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs=
github.com/bsm/ginkgo/v2 v2.12.0/go.mod h1:SwYbGRRDovPVboqFv0tPTcG1sN61LM1Z4ARdbAV9g4c=
github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA=
github.com/bsm/gomega v1.27.10/go.mod h1:JyEr/xRbxbtgWNi8tIEVPUYZ5Dzef52k01W3YH0H+O0=
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
github.com/golobby/cast v1.3.3 h1:s2Lawb9RMz7YyYf8IrfMQY4IFmA1R/lgfmj97Vc6fig=
github.com/golobby/cast v1.3.3/go.mod h1:0oDO5IT84HTXcbLDf1YXuk0xtg/cRDrxhbpWKxwtJCY=
github.com/golobby/config/v3 v3.4.2 h1:oIOSo24mC0A8f93ZTL24NDNw0hZ3Tbb34wc1ckn2CsA=
Expand All @@ -27,6 +37,8 @@ github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsK
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/redis/go-redis/v9 v9.10.0 h1:FxwK3eV8p/CQa0Ch276C7u2d0eNC9kCmAYQ7mCXCzVs=
github.com/redis/go-redis/v9 v9.10.0/go.mod h1:huWgSWd8mW6+m0VPhJjSSQ+d6Nh1VICQ6Q5lHuCH/Iw=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=
Expand All @@ -40,6 +52,8 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/yuin/gopher-lua v1.1.1 h1:kYKnWBjvbNP4XLT3+bPEwAXJx262OhaHDWDVOPjL46M=
github.com/yuin/gopher-lua v1.1.1/go.mod h1:GBR0iDaNXjAgGg9zfCvksxSRnQx76gclCIb7kdAd1Pw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
Expand Down
6 changes: 4 additions & 2 deletions modules/cache/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ func NewMemoryCache(config *CacheConfig) *MemoryCache {

// Connect initializes the memory cache
func (c *MemoryCache) Connect(ctx context.Context) error {
// Start cleanup goroutine
// Start cleanup goroutine with derived context
c.cleanupCtx, c.cancelFunc = context.WithCancel(ctx)
go c.startCleanupTimer(c.cleanupCtx)
go func() {
c.startCleanupTimer(c.cleanupCtx)
}()
return nil
}

Expand Down
41 changes: 32 additions & 9 deletions modules/cache/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import (
"context"
"fmt"
"time"

"github.com/GoCodeAlone/modular"
Expand Down Expand Up @@ -56,7 +57,7 @@
// Retrieve the registered config section for access
cfg, err := app.GetConfigSection(m.name)
if err != nil {
return err
return fmt.Errorf("failed to get config section for cache module: %w", err)

Check warning on line 60 in modules/cache/module.go

View check run for this annotation

Codecov / codecov/patch

modules/cache/module.go#L60

Added line #L60 was not covered by tests
}

m.config = cfg.GetConfig().(*CacheConfig)
Expand Down Expand Up @@ -84,15 +85,18 @@
m.logger.Info("Starting cache module")
err := m.cacheEngine.Connect(ctx)
if err != nil {
return err
return fmt.Errorf("failed to connect cache engine: %w", err)

Check warning on line 88 in modules/cache/module.go

View check run for this annotation

Codecov / codecov/patch

modules/cache/module.go#L88

Added line #L88 was not covered by tests
}
return nil
}

// Stop performs shutdown logic for the module
func (m *CacheModule) Stop(ctx context.Context) error {
m.logger.Info("Stopping cache module")
return m.cacheEngine.Close(ctx)
if err := m.cacheEngine.Close(ctx); err != nil {
return fmt.Errorf("failed to close cache engine: %w", err)
}

Check warning on line 98 in modules/cache/module.go

View check run for this annotation

Codecov / codecov/patch

modules/cache/module.go#L97-L98

Added lines #L97 - L98 were not covered by tests
return nil
}

// Dependencies returns the names of modules this module depends on
Expand Down Expand Up @@ -133,33 +137,52 @@
if ttl == 0 {
ttl = time.Duration(m.config.DefaultTTL) * time.Second
}
return m.cacheEngine.Set(ctx, key, value, ttl)
if err := m.cacheEngine.Set(ctx, key, value, ttl); err != nil {
return fmt.Errorf("failed to set cache item: %w", err)
}

Check warning on line 142 in modules/cache/module.go

View check run for this annotation

Codecov / codecov/patch

modules/cache/module.go#L141-L142

Added lines #L141 - L142 were not covered by tests
return nil
}

// Delete removes an item from the cache
func (m *CacheModule) Delete(ctx context.Context, key string) error {
return m.cacheEngine.Delete(ctx, key)
if err := m.cacheEngine.Delete(ctx, key); err != nil {
return fmt.Errorf("failed to delete cache item: %w", err)
}

Check warning on line 150 in modules/cache/module.go

View check run for this annotation

Codecov / codecov/patch

modules/cache/module.go#L149-L150

Added lines #L149 - L150 were not covered by tests
return nil
}

// Flush removes all items from the cache
func (m *CacheModule) Flush(ctx context.Context) error {
return m.cacheEngine.Flush(ctx)
if err := m.cacheEngine.Flush(ctx); err != nil {
return fmt.Errorf("failed to flush cache: %w", err)
}

Check warning on line 158 in modules/cache/module.go

View check run for this annotation

Codecov / codecov/patch

modules/cache/module.go#L157-L158

Added lines #L157 - L158 were not covered by tests
return nil
}

// GetMulti retrieves multiple items from the cache
func (m *CacheModule) GetMulti(ctx context.Context, keys []string) (map[string]interface{}, error) {
return m.cacheEngine.GetMulti(ctx, keys)
result, err := m.cacheEngine.GetMulti(ctx, keys)
if err != nil {
return nil, fmt.Errorf("failed to get multiple cache items: %w", err)
}

Check warning on line 167 in modules/cache/module.go

View check run for this annotation

Codecov / codecov/patch

modules/cache/module.go#L166-L167

Added lines #L166 - L167 were not covered by tests
return result, nil
}

// SetMulti stores multiple items in the cache
func (m *CacheModule) SetMulti(ctx context.Context, items map[string]interface{}, ttl time.Duration) error {
if ttl == 0 {
ttl = time.Duration(m.config.DefaultTTL) * time.Second
}
return m.cacheEngine.SetMulti(ctx, items, ttl)
if err := m.cacheEngine.SetMulti(ctx, items, ttl); err != nil {
return fmt.Errorf("failed to set multiple cache items: %w", err)
}

Check warning on line 178 in modules/cache/module.go

View check run for this annotation

Codecov / codecov/patch

modules/cache/module.go#L177-L178

Added lines #L177 - L178 were not covered by tests
return nil
}

// DeleteMulti removes multiple items from the cache
func (m *CacheModule) DeleteMulti(ctx context.Context, keys []string) error {
return m.cacheEngine.DeleteMulti(ctx, keys)
if err := m.cacheEngine.DeleteMulti(ctx, keys); err != nil {
return fmt.Errorf("failed to delete multiple cache items: %w", err)
}
return nil

Check warning on line 187 in modules/cache/module.go

View check run for this annotation

Codecov / codecov/patch

modules/cache/module.go#L184-L187

Added lines #L184 - L187 were not covered by tests
}
Loading
Loading