Implemented presign logic for file manager
This commit is contained in:
1 parent
fdd46f5086
commit
20cc4db097
11 files changed
+234
-141
No files matched your search
Vendored
+40
@@ -0,0 +1,40 @@
|
||||
package cache
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"time"
|
||||
)
|
||||
|
||||
func newInMemCache() Manager {
|
||||
return &inMemCache{make(map[string]inMemEntry)}
|
||||
}
|
||||
|
||||
type inMemEntry struct {
|
||||
value string
|
||||
expiration time.Time
|
||||
}
|
||||
|
||||
type inMemCache struct {
|
||||
entries map[string]inMemEntry
|
||||
}
|
||||
|
||||
func (i *inMemCache) Set(key, value string, expiration time.Duration) error {
|
||||
i.entries[key] = inMemEntry{
|
||||
value: value,
|
||||
expiration: time.Now().Add(expiration),
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (i *inMemCache) Get(key string) (string, error) {
|
||||
if val, exists := i.entries[key]; exists {
|
||||
if val.expiration.Before(time.Now()) {
|
||||
delete(i.entries, key)
|
||||
} else {
|
||||
return val.value, nil
|
||||
}
|
||||
}
|
||||
return "", errors.New("no value for given key")
|
||||
}
|
||||
func (i *inMemCache) Remove(key string) {
|
||||
delete(i.entries, key)
|
||||
}
|
||||
@@ -2,7 +2,6 @@ package cache
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"github.com/go-redis/redis/v8"
|
||||
"os"
|
||||
"time"
|
||||
@@ -37,37 +36,3 @@ func (r *redisCache) Remove(key string) {
|
||||
defer cancel()
|
||||
r.client.Del(ctx, key)
|
||||
}
|
||||
|
||||
func newInMemCache() Manager {
|
||||
return &inMemCache{make(map[string]inMemEntry)}
|
||||
}
|
||||
|
||||
type inMemEntry struct {
|
||||
value string
|
||||
expiration time.Time
|
||||
}
|
||||
|
||||
type inMemCache struct {
|
||||
entries map[string]inMemEntry
|
||||
}
|
||||
|
||||
func (i *inMemCache) Set(key, value string, expiration time.Duration) error {
|
||||
i.entries[key] = inMemEntry{
|
||||
value: value,
|
||||
expiration: time.Now().Add(expiration),
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (i *inMemCache) Get(key string) (string, error) {
|
||||
if val, exists := i.entries[key]; exists {
|
||||
if val.expiration.Before(time.Now()) {
|
||||
delete(i.entries, key)
|
||||
} else {
|
||||
return val.value, nil
|
||||
}
|
||||
}
|
||||
return "", errors.New("no value for given key")
|
||||
}
|
||||
func (i *inMemCache) Remove(key string) {
|
||||
delete(i.entries, key)
|
||||
}
|
||||
Reference in new issue
Block a user