mirror of
https://github.com/darmiel/yaxc.git
synced 2024-11-15 20:37:42 +08:00
27 lines
443 B
Go
27 lines
443 B
Go
|
package server
|
||
|
|
||
|
import (
|
||
|
"github.com/patrickmn/go-cache"
|
||
|
"time"
|
||
|
)
|
||
|
|
||
|
type CacheBackend struct {
|
||
|
c *cache.Cache
|
||
|
errCast error
|
||
|
}
|
||
|
|
||
|
func (b *CacheBackend) Get(key string) (res string, err error) {
|
||
|
if v, ok := b.c.Get(key); ok {
|
||
|
if s, ok := v.(string); ok {
|
||
|
return s, nil
|
||
|
}
|
||
|
return "", b.errCast
|
||
|
}
|
||
|
return "", nil
|
||
|
}
|
||
|
|
||
|
func (b *CacheBackend) Set(key, value string, ttl time.Duration) error {
|
||
|
b.c.Set(key, value, ttl)
|
||
|
return nil
|
||
|
}
|