From 8f8eebfda536bd622f8377ed6a94c30ef24bef16 Mon Sep 17 00:00:00 2001 From: DanB Date: Thu, 8 Mar 2018 18:51:23 +0100 Subject: [PATCH] CacheSv1.RemoveItem API --- apier/v1/caches.go | 14 ++++++++++---- engine/caches.go | 31 +++++++++++++++++++------------ glide.lock | 2 +- 3 files changed, 30 insertions(+), 17 deletions(-) diff --git a/apier/v1/caches.go b/apier/v1/caches.go index 73e32302a..487115baf 100644 --- a/apier/v1/caches.go +++ b/apier/v1/caches.go @@ -33,14 +33,20 @@ type CacheSv1 struct { cacheS *engine.CacheS } +// GetItemExpiryTime returns the expiryTime for an item +func (chSv1 *CacheSv1) GetItemIDs(args *engine.ArgsGetCacheItemIDs, + reply *[]string) error { + return chSv1.cacheS.V1GetItemIDs(args, reply) +} + // GetItemExpiryTime returns the expiryTime for an item func (chSv1 *CacheSv1) GetItemExpiryTime(args *engine.ArgsGetCacheItem, reply *time.Time) error { return chSv1.cacheS.V1GetItemExpiryTime(args, reply) } -// GetItemExpiryTime returns the expiryTime for an item -func (chSv1 *CacheSv1) GetItemIDs(args *engine.ArgsGetCacheItemIDs, - reply *[]string) error { - return chSv1.cacheS.V1GetItemIDs(args, reply) +// RemoveItem removes the Item with ID from cache +func (chSv1 *CacheSv1) RemoveItem(args *engine.ArgsGetCacheItem, + reply *string) error { + return chSv1.cacheS.V1RemoveItem(args, reply) } diff --git a/engine/caches.go b/engine/caches.go index 94e9ee2fe..2484e1b6c 100644 --- a/engine/caches.go +++ b/engine/caches.go @@ -111,6 +111,21 @@ func (chS *CacheS) Precache() (err error) { return } +type ArgsGetCacheItemIDs struct { + CacheID string + ItemIDPrefix string +} + +func (chS *CacheS) V1GetItemIDs(args *ArgsGetCacheItemIDs, + reply *[]string) (err error) { + if itmIDs := Cache.GetItemIDs(args.CacheID, args.ItemIDPrefix); len(itmIDs) == 0 { + return utils.ErrNotFound + } else { + *reply = itmIDs + } + return +} + type ArgsGetCacheItem struct { CacheID string ItemID string @@ -126,17 +141,9 @@ func (chS *CacheS) V1GetItemExpiryTime(args *ArgsGetCacheItem, return } -type ArgsGetCacheItemIDs struct { - CacheID string - ItemIDPrefix string -} - -func (chS *CacheS) V1GetItemIDs(args *ArgsGetCacheItemIDs, - reply *[]string) (err error) { - if itmIDs := Cache.GetItemIDs(args.CacheID, args.ItemIDPrefix); len(itmIDs) == 0 { - return utils.ErrNotFound - } else { - *reply = itmIDs - } +func (chS *CacheS) V1RemoveItem(args *ArgsGetCacheItem, + reply *string) (err error) { + Cache.Remove(args.CacheID, args.ItemID, true, utils.NonTransactional) + *reply = utils.OK return } diff --git a/glide.lock b/glide.lock index 53f406422..260e4af8f 100644 --- a/glide.lock +++ b/glide.lock @@ -16,7 +16,7 @@ imports: - name: github.com/cgrates/kamevapi version: e4dfe7d6cb5bb0872111fe7d61af0e1a19eda485 - name: github.com/cgrates/ltcache - version: 3aface1319c71e5050445fc659361a59bbeeedff + version: d3381f22fae3c21703341cf13aad50f116862ebd - name: github.com/cgrates/osipsdagram version: 3d6beed663452471dec3ca194137a30d379d9e8f - name: github.com/cgrates/radigo