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

Function Cache_New

src/util/cache/cache.c:57–76  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

55}
56
57Cache *Cache_New(uint cap, CacheEntryFreeFunc freeFunc, CacheEntryCopyFunc copyFunc) {
58 ASSERT(cap > 0);
59 ASSERT(copyFunc != NULL);
60
61 Cache *cache = rm_malloc(sizeof(Cache));
62 cache->cap = cap;
63 cache->size = 0;
64 cache->lookup = raxNew(); // Instantiate key entry mapping.
65 cache->counter = 0; // Initialize counter to zero.
66 cache->copy_item = copyFunc;
67 cache->free_item = freeFunc;
68 cache->arr = rm_calloc(cap, sizeof(CacheEntry)); // Array of cached values.
69
70 // Initialize the read-write lock to protect access to the cache.
71 int res = pthread_rwlock_init(&cache->_cache_rwlock, NULL);
72 UNUSED(res);
73 ASSERT(res == 0);
74
75 return cache;
76}
77
78void *Cache_GetValue(Cache *cache, const char *key) {
79 void *item = NULL;

Callers 2

GraphContext_NewFunction · 0.85
test_executionPlanCacheFunction · 0.85

Calls 2

rm_mallocFunction · 0.85
rm_callocFunction · 0.85

Tested by 1

test_executionPlanCacheFunction · 0.68