(collection string, key, value interface{}, ttl time.Duration)
| 52 | } |
| 53 | |
| 54 | func Set(collection string, key, value interface{}, ttl time.Duration) error { |
| 55 | lock.Lock() |
| 56 | defer lock.Unlock() |
| 57 | |
| 58 | if cache[collection] == nil { |
| 59 | cache[collection] = map[string]*CacheItem{} |
| 60 | } |
| 61 | |
| 62 | hash, err := hashKey(key) |
| 63 | |
| 64 | if err != nil { |
| 65 | return err |
| 66 | } |
| 67 | |
| 68 | cache[collection][hash] = &CacheItem{ |
| 69 | Item: value, |
| 70 | Expires: time.Now().Add(ttl), |
| 71 | } |
| 72 | |
| 73 | return nil |
| 74 | } |
| 75 | |
| 76 | func Clear(collection string, key interface{}) error { |
| 77 | lock.Lock() |