forked from RedisJSON/RedisJSON
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcache.h
73 lines (57 loc) · 2.06 KB
/
cache.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
* Copyright 2017-2019 Redis Labs Ltd. and Contributors
*
* This file is available under the Redis Labs Source Available License Agreement
*/
/**
* LRU Entry, per path. Stored under keys
*/
#include "rejson.h"
#include <sds.h>
typedef struct LruPathEntry {
// Prev/Next in the LRU itself
struct LruPathEntry *lru_prev;
struct LruPathEntry *lru_next;
// When deleting keys, know which keys map to which entries
struct LruPathEntry *key_next;
// When deleting an entry, remove it from the head of the key list, if
// a head.
JSONType_t *parent;
sds path;
sds value;
} LruPathEntry;
typedef struct {
LruPathEntry *newest;
LruPathEntry *oldest;
// Number of total entries within the LRU
size_t numEntries;
// Number of bytes within the LRU
size_t numBytes;
// Maximum number of allowable entries within the LRU (is this needed?)
size_t maxEntries;
// Maximum number of bytes allowed in the LRU
size_t maxBytes;
// Minimum entry size. Entries smaller than this are not used because it's usually
// cheaper to construct the response on the fly
size_t minSize;
} LruCache;
#define LRUCACHE_DEFAULT_MINSIZE 0
#define LRUCACHE_DEFAULT_MAXBYTE (1 << 20)
#define LRUCACHE_DEFAULT_MAXENT 20000
extern LruCache jsonLruCache_g;
extern int jsonLruCacheEnabled_g;
#define REJSON_LRUCACHE_GLOBAL (&jsonLruCache_g)
/**
* Get the value from the LRU cache. This renews the entry within the LRU
*/
const sds LruCache_GetValue(LruCache *cache, JSONType_t *json, const char *path, size_t pathLen);
/**
* Set the value for a given path. It is assumed that the value for the current
* path does not yet exist. This will insert
*/
void LruCache_AddValue(LruCache *cache, JSONType_t *json, const char *path, size_t pathLen,
const char *value, size_t valueLen);
// Clear all cache items for a given path
void LruCache_ClearValues(LruCache *cache, JSONType_t *json, const char *path, size_t pathLen);
// Clears all values for a given key
void LruCache_ClearKey(LruCache *cache, JSONType_t *json);