-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/Optional Database Caching #90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
📊 Test Coverage Report✅ Total Coverage: 90.4% 📋 View Detailed Report |
char2cs
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sacando los comentarios, buena implementación y usás bien los conceptos de Go. Trataría de reducir la cantidad de archivos y aplicar mejor algunos conceptos del lenguaje, pero le estás agarrando la mano.
… to return an unmarshal error but it checked for if there was none. Updated logic to assert expected behaviour. Checking for if: 1. found == true then error == nil else 2. found == false then error != nil && error contains "unmarshal"
�[0;32mCode formatted!�[0m (mala mia chicos jajajaj)
…alues in internal/core/database/cache/config.go
…sitory. Fixed tests. Removed unused field Context from builder.go.
…go to satisfy new RepositoryInterface
9bba170 to
cf9df25
Compare
…go up to 94.4%. Fixed missing error handling and implemented use of Watcher.Warn for configuration errors and cache write failure
…tory.go constructor.
📊 Test Coverage Report✅ Total Coverage: 90.9% 📋 View Detailed Report |
📊 Test Coverage Report✅ Total Coverage: 90.9% 📋 View Detailed Report |
| return nil, err | ||
| } | ||
|
|
||
| for _, entity := range result { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aca valen guarda, estamos reimplementando la funcion del repositorio para guardar.
La capa de cache deberia ser un wrapper por sobre el repositorio original:
v, found := cr.cache.GetById(key) // Primero buscamos en cache
if found {
data, ok := v.([]byte)
if !ok {
return nil, cacheerr.ErrInvalidCacheValue
}
var result []*T
err := json.Unmarshal(data, &result)
if err != nil {
return nil, err
}
return result, nil // Si esta devolvemos eso
}
entity, err := baseRepository.GetById() // Si no fallbackeamos al repositorio original
if err != nil {
return err
}
go cr.cache.AsyncSet(entity) // Asincronicamente hidratamos el cache
return entity // Y devolvemos la respuesta…r a method/function to retrieve keys from a (signature .
📊 Test Coverage Report✅ Total Coverage: 90.8% 📋 View Detailed Report |
Description
Implements an optional in-memory caching layer for the Core database module using the builder pattern. The cache wraps the base database interface with a cache layer (decorator pattern) to improve read performance and reduce database I/O. This is step 1 of the broader persistence initiative.
Type of Change
Related Issues
Closes #59
Changes Made
Cacheinterface withGet,Set,Delete, andFlushmethods supporting TTLGoCacheusinggithub.com/patrickmn/go-cachelibrary (as specified in issue Core / Database / Cache Abstraction Layer #59)RepositoryCachedecorator that wraps base repository with transparent cachingDatabaseBuilderpattern with optionalWithCache()method for flexible compositioncache.enabled,cache.default_ttl,cache.cleanup_interval)default.yaml(disabled by default)CacheConfigNewDatabase()function still works without changesgithub.com/patrickmn/go-cachedependency (v2.1.0+incompatible)New Files
internal/core/database/cache/interface.go- Cache interface definitioninternal/core/database/cache/config.go- Cache configuration struct and defaultsinternal/core/database/cache/memory_cache.go- Alternative in-memory cache implementation (used in tests, not in production code)internal/core/database/cache/gocache.go- go-cache implementation usinggithub.com/patrickmn/go-cacheinternal/core/database/cache/repository_cache.go- Repository decorator with cachinginternal/core/database/cache/config_helper.go- YAML config to CacheConfig converterinternal/core/database/builder.go- DatabaseBuilder pattern implementationinternal/core/database/cache/cache_test.go- Cache interface testsinternal/core/database/cache/repository_cache_test.go- Repository cache testsinternal/core/database/builder_test.go- Builder pattern testsinternal/core/database/integration_test.go- Integration testsModified Files
internal/core/config/config.go- Added Cache struct and GetCache() functioninternal/core/config/default.yaml- Added cache configuration sectiongo.mod- Addedgithub.com/patrickmn/go-cachedependencyBreaking Changes
Migration Guide
No breaking changes. The cache is optional and disabled by default. Existing code using
NewDatabase()continues to work without modification. This is a purely additive feature.To enable caching, use the new builder pattern:
Or enable via configuration file:
Checklist
./docs/foldermake test)make test-coverage)make lint)make security)Screenshots/Logs (if applicable)
Test Coverage Summary
Key Features
go-cachelibrary which is thread-safe by designgithub.com/patrickmn/go-cacheas specified in issue Core / Database / Cache Abstraction Layer #59