| 21 | ) |
| 22 | |
| 23 | func Get(collection string, key interface{}) interface{} { |
| 24 | lock.Lock() |
| 25 | defer lock.Unlock() |
| 26 | |
| 27 | if os.Getenv("PROVIDER") == "test" { |
| 28 | return nil |
| 29 | } |
| 30 | |
| 31 | hash, err := hashKey(key) |
| 32 | |
| 33 | if err != nil { |
| 34 | return nil |
| 35 | } |
| 36 | |
| 37 | if cache[collection] == nil { |
| 38 | return nil |
| 39 | } |
| 40 | |
| 41 | item := cache[collection][hash] |
| 42 | |
| 43 | if item == nil { |
| 44 | return nil |
| 45 | } |
| 46 | |
| 47 | if item.Expires.Before(time.Now()) { |
| 48 | return nil |
| 49 | } |
| 50 | |
| 51 | return item.Item |
| 52 | } |
| 53 | |
| 54 | func Set(collection string, key, value interface{}, ttl time.Duration) error { |
| 55 | lock.Lock() |