See Storage for documentation.
(
keys ...interface{})
| 46 | |
| 47 | // See Storage for documentation. |
| 48 | func (s *CacheOnStorage) GetMulti( |
| 49 | keys ...interface{}) ([]interface{}, error) { |
| 50 | |
| 51 | results, err := s.cache.GetMulti(keys...) |
| 52 | if err != nil { |
| 53 | return nil, err |
| 54 | } |
| 55 | |
| 56 | indices := make([]int, 0, len(keys)) |
| 57 | uncachedKeys := make([]interface{}, 0, len(keys)) |
| 58 | for i, item := range results { |
| 59 | if item == nil { |
| 60 | indices = append(indices, i) |
| 61 | uncachedKeys = append(uncachedKeys, keys[i]) |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | uncachedItems, err := s.storage.GetMulti(uncachedKeys...) |
| 66 | if err != nil { |
| 67 | return nil, err |
| 68 | } |
| 69 | |
| 70 | foundItems := make([]interface{}, 0, len(uncachedItems)) |
| 71 | for _, item := range uncachedItems { |
| 72 | if item != nil { |
| 73 | foundItems = append(foundItems, item) |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | if err := s.cache.SetMulti(foundItems...); err != nil { |
| 78 | // XXX: Maybe make this a non error |
| 79 | return nil, err |
| 80 | } |
| 81 | |
| 82 | for i, index := range indices { |
| 83 | results[index] = uncachedItems[i] |
| 84 | } |
| 85 | |
| 86 | return results, nil |
| 87 | } |
| 88 | |
| 89 | // See Storage for documentation. |
| 90 | func (s *CacheOnStorage) Set(item interface{}) error { |