Skip to content

Commit

Permalink
Added ResetCache function to reset the all in-memory cache.
Browse files Browse the repository at this point in the history
  • Loading branch information
vhadianto committed Dec 22, 2024
1 parent a3efb34 commit 5ae8a13
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

Shared Pipes Component

## v1.7.1 [tbd]

_What's new_

* Added `ResetCache` function to reset the all in-memory cache.

## v1.7.0 [2024-12-20]

_What's new_
Expand Down
15 changes: 13 additions & 2 deletions cache/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ var (
connectionCacheInitOnce sync.Once
)

func inMemoryInitialize(config *ristretto.Config) *InMemoryCache {
func initializeInMemoryCache(config *ristretto.Config) *InMemoryCache {
if config == nil {
config = &ristretto.Config{
NumCounters: 100000, // number of keys to track frequency
Expand All @@ -43,7 +43,7 @@ func inMemoryInitialize(config *ristretto.Config) *InMemoryCache {

func GetCache() *InMemoryCache {
inMemoryCacheInitOnce.Do(func() {
inMemoryInitialize(nil)
initializeInMemoryCache(nil)
})
return inMemoryCache
}
Expand Down Expand Up @@ -104,6 +104,17 @@ func ResetConnectionCache() {
initializeConnectionCache()
}

func ResetInMemoryCache() {
inMemoryCache = nil
initializeInMemoryCache(nil)
}

func ResetAllCache() {
ResetCredentialCache()
ResetConnectionCache()
ResetInMemoryCache()
}

func (cache *InMemoryCache) SetWithTTL(key string, value interface{}, ttl time.Duration) bool {
res := cache.cache.SetWithTTL(key, value, 1, ttl)

Expand Down

0 comments on commit 5ae8a13

Please sign in to comment.