/* * The front door to cgit's page cache. A caller hands over a key identifying * the request and a callback that renders the page, and gets back either the * copy already on disk or a freshly rendered one. */ #ifndef CGIT_CACHE_H #define CGIT_CACHE_H #include typedef void (*cache_fill_fn)(void); /* * Write the page for key to stdout, taking it from the cache when a fresh * slot for that key is there and rendering it through fn when it is not. size * is how many slots the cache may use and path is the directory holding them. * ttl is how many minutes a slot for this key stays fresh, where a negative * ttl never expires and a ttl of zero skips the cache for this request. A * page larger than max_bytes is served but not kept, and zero sets no bound. * Returns 0 when the page was written, and an errno value when it was not. */ extern int cache_process(int size, const char *path, const char *key, int ttl, size_t max_bytes, cache_fill_fn fn); /* * Write one line per cache slot to stdout, giving its path, modification time, * size and key. */ extern int cache_ls(const char *path); /* * Give up on the slot being filled and put stdout back on the client, after * sending what was rendered into the slot so far. Anything that ends a request * part way through rendering has to call this before it writes what the * visitor should see, because until then stdout is the cache file. Returns * non-zero when a fill was abandoned and zero when none was in progress. */ extern int cache_abandon_fill(void); extern unsigned long cache_hash_str(const char *str); #endif // CGIT_CACHE_H