uses set instead of add for memcache

set always sets the value regardless.
This commit is contained in:
bergquist 2019-03-03 12:34:41 +01:00
parent 8db2864fee
commit 33935b09f0
5 changed files with 12 additions and 26 deletions

View File

@ -4,9 +4,5 @@ import "testing"
func TestIntegrationDatabaseCacheStorage(t *testing.T) {
client := createTestClient(t, "database")
CanPutGetAndDeleteCachedObjects(t, client)
CanNotFetchExpiredItems(t, client)
CanSetInfiniteCacheExpiration(t, client)
RunTestsForClient(t, createTestClient(t, "database"))
}

View File

@ -26,16 +26,16 @@ func createTestClient(t *testing.T, name string) cacheStorage {
return createClient(CacheOpts{name: name}, sqlstore)
}
func TestAllCacheClients(t *testing.T) {
clients := []string{"memory"} // add redis, memcache, memory
func TestMemoryStorageClient(t *testing.T) {
for _, v := range clients {
client := createTestClient(t, v)
client := createTestClient(t, "memory")
RunTestsForClient(t, client)
}
CanPutGetAndDeleteCachedObjects(t, client)
CanNotFetchExpiredItems(t, client)
CanSetInfiniteCacheExpiration(t, client)
}
func RunTestsForClient(t *testing.T, client cacheStorage) {
CanPutGetAndDeleteCachedObjects(t, client)
CanNotFetchExpiredItems(t, client)
CanSetInfiniteCacheExpiration(t, client)
}
func CanPutGetAndDeleteCachedObjects(t *testing.T, client cacheStorage) {

View File

@ -35,7 +35,7 @@ func (s *memcacheStorage) Put(key string, val interface{}, expires time.Duration
memcacheItem := newItem(key, bytes, int32(expires))
return s.c.Add(memcacheItem)
return s.c.Set(memcacheItem)
}
// Get gets value by given key in the cache.

View File

@ -3,10 +3,5 @@ package distcache
import "testing"
func TestMemcachedCacheStorage(t *testing.T) {
client := createTestClient(t, "memcache")
CanPutGetAndDeleteCachedObjects(t, client)
CanNotFetchExpiredItems(t, client)
CanSetInfiniteCacheExpiration(t, client)
RunTestsForClient(t, createTestClient(t, "memcache"))
}

View File

@ -3,10 +3,5 @@ package distcache
import "testing"
func TestRedisCacheStorage(t *testing.T) {
client := createTestClient(t, "redis")
CanPutGetAndDeleteCachedObjects(t, client)
CanNotFetchExpiredItems(t, client)
CanSetInfiniteCacheExpiration(t, client)
RunTestsForClient(t, createTestClient(t, "redis"))
}