mirror of
https://github.com/ivuorinen/gh-action-readme.git
synced 2026-02-05 19:45:39 +00:00
chore: even more linting, test fixes (#24)
* chore(lint): funcorder * chore(lint): yamlfmt, ignored broken test yaml files * chore(tests): tests do not output garbage, add coverage * chore(lint): fix editorconfig violations * chore(lint): move from eclint to editorconfig-checker * chore(lint): add pre-commit, run and fix * chore(ci): we use renovate to manage updates
This commit is contained in:
38
internal/cache/cache.go
vendored
38
internal/cache/cache.go
vendored
@@ -196,6 +196,25 @@ func (c *Cache) Close() error {
|
||||
return c.saveToDisk()
|
||||
}
|
||||
|
||||
// GetOrSet retrieves a value from cache or sets it if not found.
|
||||
func (c *Cache) GetOrSet(key string, getter func() (any, error)) (any, error) {
|
||||
// Try to get from cache first
|
||||
if value, exists := c.Get(key); exists {
|
||||
return value, nil
|
||||
}
|
||||
|
||||
// Not in cache, get from source
|
||||
value, err := getter()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Store in cache
|
||||
_ = c.Set(key, value) // Log error but don't fail - we have the value
|
||||
|
||||
return value, nil
|
||||
}
|
||||
|
||||
// cleanupLoop runs periodically to remove expired entries.
|
||||
func (c *Cache) cleanupLoop() {
|
||||
for {
|
||||
@@ -289,22 +308,3 @@ func (c *Cache) estimateSize(value any) int64 {
|
||||
|
||||
return int64(len(jsonData))
|
||||
}
|
||||
|
||||
// GetOrSet retrieves a value from cache or sets it if not found.
|
||||
func (c *Cache) GetOrSet(key string, getter func() (any, error)) (any, error) {
|
||||
// Try to get from cache first
|
||||
if value, exists := c.Get(key); exists {
|
||||
return value, nil
|
||||
}
|
||||
|
||||
// Not in cache, get from source
|
||||
value, err := getter()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Store in cache
|
||||
_ = c.Set(key, value) // Log error but don't fail - we have the value
|
||||
|
||||
return value, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user