initial commit

This commit is contained in:
2024-08-01 23:42:30 +03:00
commit 09fef3c113
21 changed files with 931 additions and 0 deletions

5
inmemorycache/go.mod Normal file
View File

@@ -0,0 +1,5 @@
module git.derfenix.pro/fenix/commander/inmemorycache
go 1.22
require github.com/patrickmn/go-cache v2.1.0+incompatible

2
inmemorycache/go.sum Normal file
View File

@@ -0,0 +1,2 @@
github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc=
github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ=

View File

@@ -0,0 +1,30 @@
package inmemorycache
import (
"time"
"github.com/patrickmn/go-cache"
)
type InMemoryCache struct {
cache *cache.Cache
}
func NewInMemoryCache() *InMemoryCache {
return &InMemoryCache{cache: cache.New(time.Minute, 5*time.Minute)}
}
func (i *InMemoryCache) Set(key string, value []byte, ttl time.Duration) error {
i.cache.Set(key, value, ttl)
return nil
}
func (i *InMemoryCache) Get(key string) ([]byte, error) {
res, ok := i.cache.Get(key)
if !ok {
return nil, nil
}
return res.([]byte), nil
}