/* * 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 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. * 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, 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, discarding what has been rendered into it * and putting stdout back on the client. 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 and the visitor is on * course to receive nothing at all. Does nothing when no slot is being filled. */ extern void cache_abandon_fill(void); extern unsigned long cache_hash_str(const char *str); #endif // CGIT_CACHE_H