Commit Graph

11 Commits

Author SHA1 Message Date
Yuxuan Shui d1888b612c
cache: zero initialize the key string
I thought `cvalloc` wraps `calloc`, but it's `malloc`...

Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
2024-02-18 01:16:58 +00:00
Yuxuan Shui 5fa870ae66
cache: support string without a NUL terminator
Also we, by which I mean me, might have been using HASH_ADD_STR wrong...

Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
2024-02-18 00:56:20 +00:00
Yuxuan Shui 96de4f07ca
cache: remove unused function cache_invalidate
Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
2024-02-16 00:42:22 +00:00
Yuxuan Shui a93bbc30e5
atom: get_atom now requires explicit xcb_connection_t
This is to make the access to X server more explicit, and make managing
the lifetime of xcb_connection_t a bit easier.

Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
2024-02-16 00:38:40 +00:00
Yuxuan Shui 6315faed20
cache: redesign
cache uses an invasive design now, a la list.h and uthash. This get rid
of the ugly integer to pointer cache, and gives us freedom of what we
can put into the cache.

Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
2024-02-16 00:38:38 +00:00
Yuxuan Shui 0dcca2228e
cache: slight refactor
Added a pure version of `cache_get` which does not change the cache, and
renamed the old `cache_get` to `cache_get_or_fetch`.

Remove unused `cache_set`, and remove prefix underscore from function
names.

Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
2024-02-15 20:07:34 +00:00
Yuxuan Shui e3d4ce6612
cache: add cache_set for testing
Also add documentation for the cache functions.

Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
2020-12-26 07:25:34 +00:00
Yuxuan Shui 0ba7761bd5
Untangle headers
Thanks, clang -fmodules.

Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
2019-08-10 00:56:26 +01:00
Yuxuan Shui 76c484885d
cache: cache_get can now return error
Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
2019-05-21 20:15:33 +01:00
Yuxuan Shui 93e4a53d48
cache: fix memory leak, add missing function
Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
2019-05-21 20:15:33 +01:00
Yuxuan Shui c08fd08ea4
Add a general key-value caching framework
Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
2019-05-21 20:15:33 +01:00