Skip to content

Commit

Permalink
[NEEDS CLEAN-UP]: Working O(n) Cache
Browse files Browse the repository at this point in the history
  • Loading branch information
SudeepRed committed Nov 4, 2023
1 parent eca16d6 commit ad0c83a
Show file tree
Hide file tree
Showing 5 changed files with 268 additions and 348 deletions.
20 changes: 20 additions & 0 deletions src/include/pgagroal.h
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,11 @@ extern void* prometheus_cache_shmem;
* response cache.
*/
extern void* query_cache_shmem;
/**
* Shared memory used to contain the Prometheus
* response cache.
*/
extern void* client_server_shmem;

/** @struct
* Defines a server
Expand Down Expand Up @@ -359,6 +364,13 @@ struct prometheus_cache
size_t size; /**< size of the cache */
char data[]; /**< the payload */
} __attribute__ ((aligned (64)));
struct client_server_cache
{
char kind;
atomic_schar lock;
size_t key_length;
char key[];
} __attribute__ ((aligned (64)));

/** @struct
* Defines the Prometheus metrics
Expand Down Expand Up @@ -424,6 +436,13 @@ struct query_cache
atomic_schar lock; /**< lock to protect the cache */
size_t size; /**< size of the cache */
struct hashTable* table;
struct cachev2
{
struct hashEntry* key;
struct hashEntry* data;
} cache[100000];
int max_elements;

} __attribute__ ((aligned (64)));

struct hashTable
Expand All @@ -437,6 +456,7 @@ struct hashEntry
{
void* value;
size_t length;
char key[];
} __attribute__ ((aligned (64)));

/** @struct
Expand Down
2 changes: 1 addition & 1 deletion src/include/query_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ pgagroal_query_cache_init(size_t* p_size, void** p_shmem);
*
* @warning The caller should ensure the validity of the 'Table' pointer and the 'key' pointer.
*/
struct hashTable*
struct hashEntry*
pgagroal_query_cache_get(struct query_cache* cache, struct hashTable** Table, struct hashEntry* key);

/**
Expand Down
Loading

0 comments on commit ad0c83a

Please sign in to comment.