Vala cache library with a shared cache API and multiple storage backends.
- Overview
- Implemented Backends
- Core API
- Quick Usage
- Build
- Test
- Release artifacts
- Use generated library in other projects
- Install via Vamposer
- Dependencies
- License
This project provides:
- common cache interface (
CacheInterface) - common cache item interface (
CacheItemInterface) - in-memory backend
- filesystem backend with persisted items
TTL constants are available in the ValaTux.CacheManager namespace:
DEFAULT_TTLTTL_MINUTE,TTL_HOUR,TTL_DAY,TTL_WEEK,TTL_MONTH,TTL_YEARTTL_INFINITE
Namespace: ValaTux.CacheManager.Memory
- stores items in RAM
- no serialization required
- supports
save,getItem,getItems,hasItem, delete operations, andclear
Namespace: ValaTux.CacheManager.Filesystem
- stores items as
.cachefiles in a cache directory - uses hashed key names for file paths
- supports persistence across process restarts
- supports JSON payloads via
GLib.ValuewithJson.Node
Supported filesystem value types:
stringint,int64uint,uint64booldoubleJson.Node
Cache:
CacheItemInterface? getItem (string key)CacheItemInterface[] getItems (string[] keys)bool hasItem (string key)bool clear ()bool deleteItem (string key)bool deleteItems (string[] keys)bool save (CacheItemInterface item)bool saveItems (CacheItemInterface[] items)bool saveDeferred (CacheItemInterface item)bool commit ()
Cache item:
string getKey ()Value? getValue ()bool IsHit ()CacheItemInterface setValue (Value? value, int ttl = 0)CacheItemInterface expireAfter (int ttl)CacheItemInterface expireAt (int timestamp)
using GLib;
using ValaTux.CacheManager;
var cache = new ValaTux.CacheManager.Memory.Cache ();
var item = new ValaTux.CacheManager.Memory.CacheItem ("user:1");
Value value = Value (typeof (string));
value.set_string ("alice");
item.setValue (value, (int) TTL_MINUTE);
cache.save (item);
CacheItemInterface? loaded = cache.getItem ("user:1");
if (loaded != null && loaded.IsHit ()) {
Value? loaded_value = loaded.getValue ();
stdout.printf ("%s\n", loaded_value.get_string ());
}using GLib;
using Json;
using ValaTux.CacheManager;
var cache = new ValaTux.CacheManager.Filesystem.Cache ();
var item = new ValaTux.CacheManager.Filesystem.CacheItem ("profile");
var parser = new Json.Parser ();
parser.load_from_data ("{\"name\":\"alice\",\"age\":30}", -1);
Value value = Value (typeof (Json.Node));
value.set_boxed (parser.get_root ().copy ());
item.setValue (value, (int) TTL_HOUR);
cache.save (item);meson setup builddir
meson compile -C builddirmeson test -C builddiror via Makefile helper:
make testsTag-based release workflow (v*) publishes:
- shared library (
lib*.so*) - generated VAPI (
src/vapi/*.vapi) - generated header (
src/*.h) - bundled ZIP (
<repo-name>-<tag>-linux.zip)
In consumer project root:
./init.shOr run directly from GitHub:
curl -sSfL https://raw.githubusercontent.com/ValaTux/cache-manager/master/init.sh -o init.sh && chmod +x init.sh && ./init.sh && rm init.shIn consumer project root:
curl -sSfL https://raw.githubusercontent.com/ValaTux/cache-manager/master/init-local-vapi.sh | bashThis helper downloads release artifacts (or builds from source) and prepares local vapi/, lib/, and include/ folders plus reusable Meson variables.
Install via Vamposer
In your consumer project root:
vamposer require ValaTux/cache-manager master
vamposer installThen include generated Vamposer dependencies in your meson.build:
subdir('vamposer')
executable('my-app',
sources,
dependencies: [
vamposer_deps
]
)You can also use a fixed tag or commit instead of master.
If you also want the test workspace, install it as a development dependency:
vamposer require --dev ValaTux/testcases master
vamposer install --dev- glib-2.0
- gio-2.0
- gee-0.8
- json-glib-1.0
- vala_testcases (tests only)
MIT (see LICENSE).