Set cached value with key and expire time.
(key string, val interface{}, timeout time.Duration)
| 42 | |
| 43 | // Set cached value with key and expire time. |
| 44 | func (mem *Memcache) Set(key string, val interface{}, timeout time.Duration) (err error) { |
| 45 | var data []byte |
| 46 | if data, err = json.Marshal(val); err != nil { |
| 47 | return err |
| 48 | } |
| 49 | |
| 50 | item := &memcache.Item{Key: key, Value: data, Expiration: int32(timeout / time.Second)} |
| 51 | return mem.conn.Set(item) |
| 52 | } |
| 53 | |
| 54 | // Delete delete value in memcache. |
| 55 | func (mem *Memcache) Delete(key string) error { |