mirror of
https://github.com/kevin-DL/services.git
synced 2026-01-22 15:25:19 +00:00
set ttl
This commit is contained in:
10
cache/handler/cache.go
vendored
10
cache/handler/cache.go
vendored
@@ -21,7 +21,9 @@ func (c *Cache) Get(ctx context.Context, req *pb.GetRequest, rsp *pb.GetResponse
|
|||||||
|
|
||||||
var value interface{}
|
var value interface{}
|
||||||
|
|
||||||
if err := cache.Context(ctx).Get(req.Key, &value); err != nil {
|
expires, err := cache.Context(ctx).Get(req.Key, &value)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
if !strings.Contains(err.Error(), "not found") {
|
if !strings.Contains(err.Error(), "not found") {
|
||||||
log.Errorf("Error querying cache %s", err)
|
log.Errorf("Error querying cache %s", err)
|
||||||
return errors.InternalServerError("cache.get", "Error querying cache")
|
return errors.InternalServerError("cache.get", "Error querying cache")
|
||||||
@@ -32,6 +34,12 @@ func (c *Cache) Get(ctx context.Context, req *pb.GetRequest, rsp *pb.GetResponse
|
|||||||
rsp.Key = req.Key
|
rsp.Key = req.Key
|
||||||
// set the value
|
// set the value
|
||||||
rsp.Value = fmt.Sprintf("%v", value)
|
rsp.Value = fmt.Sprintf("%v", value)
|
||||||
|
// set the ttl
|
||||||
|
rsp.Ttl = int64(expires.Sub(time.Now()).Seconds())
|
||||||
|
|
||||||
|
if rsp.Ttl < 0 {
|
||||||
|
rsp.Ttl = 0
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user