func (rs *RedisStorage) GetActions(key string, skipCache bool, transactionID string) (as Actions, err error) { key = utils.ACTION_PREFIX + key if !skipCache { if x, err := cache.GetCloned(key); err != nil { if err.Error() != utils.ItemNotFound { return nil, err } } else if x == nil { return nil, utils.ErrNotFound } else { return x.(Actions), nil } } var values []byte if values, err = rs.Cmd("GET", key).Bytes(); err != nil { if err.Error() == "wrong type" { // did not find the destination cache.Set(key, nil, cacheCommit(transactionID), transactionID) err = utils.ErrNotFound } return } if err = rs.ms.Unmarshal(values, &as); err != nil { return } cache.Set(key, as, cacheCommit(transactionID), transactionID) return }
func (ms *MapStorage) GetActions(key string, skipCache bool, transactionID string) (as Actions, err error) { ms.mu.RLock() defer ms.mu.RUnlock() cCommit := cacheCommit(transactionID) key = utils.ACTION_PREFIX + key if !skipCache { if x, err := cache.GetCloned(key); err != nil { if err.Error() != utils.ItemNotFound { return nil, err } } else if x == nil { return nil, utils.ErrNotFound } else { return x.(Actions), nil } } if values, ok := ms.dict[key]; ok { err = ms.ms.Unmarshal(values, &as) } else { cache.Set(key, nil, cCommit, transactionID) return nil, utils.ErrNotFound } cache.Set(key, as, cCommit, transactionID) return }
func TestCacheGetCloned(t *testing.T) { at1 := &ActionPlan{ Id: "test", AccountIDs: utils.StringMap{"one": true, "two": true, "three": true}, } cache.Set("MYTESTAPL", at1, true, "") clned, err := cache.GetCloned("MYTESTAPL") if err != nil { t.Error(err) } at1Cloned := clned.(*ActionPlan) if !reflect.DeepEqual(at1, at1Cloned) { t.Errorf("Expecting: %+v, received: %+v", at1, at1Cloned) } }
func (rs *RedisStorage) GetActionPlan(key string, skipCache bool, transactionID string) (ats *ActionPlan, err error) { key = utils.ACTION_PLAN_PREFIX + key if !skipCache { if x, err := cache.GetCloned(key); err != nil { if err.Error() != utils.ItemNotFound { // Only consider cache if item was found return nil, err } } else if x == nil { // item was placed nil in cache return nil, utils.ErrNotFound } else { return x.(*ActionPlan), nil } } var values []byte if values, err = rs.Cmd("GET", key).Bytes(); err != nil { if err.Error() == "wrong type" { // did not find the destination cache.Set(key, nil, cacheCommit(transactionID), transactionID) err = utils.ErrNotFound } return } b := bytes.NewBuffer(values) r, err := zlib.NewReader(b) if err != nil { return nil, err } out, err := ioutil.ReadAll(r) if err != nil { return nil, err } r.Close() if err = rs.ms.Unmarshal(out, &ats); err != nil { return } cache.Set(key, ats, cacheCommit(transactionID), transactionID) return }