Skip to content

Commit

Permalink
Merge pull request #26 from rfyiamcool/fix/err_cache_expired
Browse files Browse the repository at this point in the history
fix: return cachego.ErrCacheExpired
  • Loading branch information
faabiosr committed May 8, 2023
2 parents 89077fa + 17fa5c1 commit ba1473f
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 6 deletions.
2 changes: 1 addition & 1 deletion bolt/bolt.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (b *bolt) read(key string) (*boltContent, error) {

if content.Duration <= time.Now().Unix() {
_ = b.Delete(key)
return nil, errors.New("cache expired")
return nil, cachego.ErrCacheExpired
}

return content, nil
Expand Down
5 changes: 2 additions & 3 deletions mongo/mongo.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package mongo

import (
"context"
"errors"
"time"

"github.com/faabiosr/cachego"
Expand Down Expand Up @@ -50,7 +49,7 @@ func (m *mongoCache) Fetch(key string) (string, error) {
content := &mongoContent{}
result := m.collection.FindOne(context.TODO(), bson.M{"_id": bson.M{"$eq": key}})
if result == nil {
return "", errors.New("cache expired")
return "", cachego.ErrCacheExpired
}
if result.Err() != nil {
return "", result.Err()
Expand All @@ -66,7 +65,7 @@ func (m *mongoCache) Fetch(key string) (string, error) {

if content.Duration <= time.Now().Unix() {
_ = m.Delete(key)
return "", errors.New("cache expired")
return "", cachego.ErrCacheExpired
}
return content.Value, nil
}
Expand Down
3 changes: 1 addition & 2 deletions sqlite3/sqlite3.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package sqlite3

import (
"database/sql"
"errors"
"fmt"
"time"

Expand Down Expand Up @@ -93,7 +92,7 @@ func (s *sqlite3) Fetch(key string) (string, error) {

if lifetime <= time.Now().Unix() {
_ = s.Delete(key)
return "", errors.New("cache expired")
return "", cachego.ErrCacheExpired
}

return value, nil
Expand Down

0 comments on commit ba1473f

Please sign in to comment.