Get - searches for given key in the cache and returns value if found
(key []byte)
| 41 | |
| 42 | // Get - searches for given key in the cache and returns value if found |
| 43 | func (c *BoltCache) Get(key []byte) (value []byte, err error) { |
| 44 | |
| 45 | err = c.DS.View(func(tx *bolt.Tx) error { |
| 46 | bucket := tx.Bucket(c.CurrentBucket) |
| 47 | if bucket == nil { |
| 48 | return fmt.Errorf("Bucket %q not found!", c.CurrentBucket) |
| 49 | } |
| 50 | // "Byte slices returned from Bolt are only valid during a transaction." |
| 51 | var buffer bytes.Buffer |
| 52 | val := bucket.Get(key) |
| 53 | |
| 54 | // If it doesn't exist then it will return nil |
| 55 | if val == nil { |
| 56 | return fmt.Errorf("key %q not found \n", key) |
| 57 | } |
| 58 | |
| 59 | buffer.Write(val) |
| 60 | value = buffer.Bytes() |
| 61 | return nil |
| 62 | }) |
| 63 | |
| 64 | return |
| 65 | } |
| 66 | |
| 67 | // GetAllValues - returns all values |
| 68 | func (c *BoltCache) GetAllValues() (values [][]byte, err error) { |