MCPcopy Create free account
hub / github.com/RedisGraph/RedisGraph / _Cache_SetValue

Function _Cache_SetValue

src/util/cache/cache.c:23–55  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

21}
22
23static bool _Cache_SetValue(Cache *cache, const char *key, void *value,
24 size_t key_len) {
25 ASSERT(key != NULL);
26 ASSERT(cache != NULL);
27
28 /* in case that another working thread had already inserted the item to the
29 * cache, no need to re-insert it */
30 CacheEntry *entry = raxFind(cache->lookup, (unsigned char *)key, key_len);
31 if(entry != raxNotFound) {
32 return false;
33 }
34
35 // key is not in cache! test to see if cache is full?
36 if(cache->size == cache->cap) {
37 /* the cache is full, evict the least-recently-used element
38 * and reuse its space for the new element */
39 entry = _CacheEvictLRU(cache);
40 } else {
41 // the array has space left in it, use the next available entry
42 entry = cache->arr + cache->size++;
43 }
44
45 // populate the entry
46 char *k = rm_strdup(key);
47 cache->counter++;
48 CacheArray_PopulateEntry(cache->counter, entry, k, value);
49
50
51 // Add the new entry to the rax.
52 raxInsert(cache->lookup, (unsigned char *)key, key_len, entry, NULL);
53
54 return true;
55}
56
57Cache *Cache_New(uint cap, CacheEntryFreeFunc freeFunc, CacheEntryCopyFunc copyFunc) {
58 ASSERT(cap > 0);

Callers 2

Cache_SetValueFunction · 0.85
Cache_SetGetValueFunction · 0.85

Calls 3

_CacheEvictLRUFunction · 0.85
rm_strdupFunction · 0.85
CacheArray_PopulateEntryFunction · 0.85

Tested by

no test coverage detected