Nilorea Library
C utilities for networking, threading, graphics
Loading...
Searching...
No Matches
n_disk_cache.h
Go to the documentation of this file.
1/*
2 * Nilorea Library
3 * Copyright (C) 2005-2026 Castagnier Mickael
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
14 * implied. See the License for the specific language governing
15 * permissions and limitations under the License.
16 *
17 * SPDX-License-Identifier: Apache-2.0
18 */
19
54
55#ifndef __NILOREA_DISK_CACHE__
56#define __NILOREA_DISK_CACHE__
57
58#ifdef __cplusplus
59extern "C" {
60#endif
61
66
67#include <stddef.h>
68#include <stdint.h>
69
70#include "nilorea/n_common.h"
71
73#define N_DISK_CACHE_NAME_LEN 32
74
77typedef struct N_DISK_CACHE N_DISK_CACHE;
78
91
99
107const char* n_disk_cache_dir(const N_DISK_CACHE* cache);
108
122int n_disk_cache_path(const N_DISK_CACHE* cache, const void* key, size_t key_len, const char* ext, char* out, size_t out_len);
123
138int n_disk_cache_put(const N_DISK_CACHE* cache, const void* key, size_t key_len, const char* ext, const void* data, size_t len);
139
155int n_disk_cache_get(const N_DISK_CACHE* cache, const void* key, size_t key_len, const char* ext, size_t max_len, unsigned char** data, size_t* len);
156
168int n_disk_cache_remove(const N_DISK_CACHE* cache, const void* key, size_t key_len, const char* ext);
169
179int n_disk_cache_size(const N_DISK_CACHE* cache, uint64_t* total);
180
193int n_disk_cache_prune(const N_DISK_CACHE* cache, uint64_t max_bytes);
194
213int n_disk_cache_prune_group(const N_DISK_CACHE* const* caches, int count, uint64_t max_bytes);
214
225int n_disk_cache_expire(const N_DISK_CACHE* cache, int64_t max_age_seconds);
226
228
229#ifdef __cplusplus
230}
231#endif
232#endif /* __NILOREA_DISK_CACHE__ */
volatile char key[227]
TRUE while the key is held.
const char * n_disk_cache_dir(const N_DISK_CACHE *cache)
The cache's directory, as it was opened.
int n_disk_cache_get(const N_DISK_CACHE *cache, const void *key, size_t key_len, const char *ext, size_t max_len, unsigned char **data, size_t *len)
Read an entry.
int n_disk_cache_path(const N_DISK_CACHE *cache, const void *key, size_t key_len, const char *ext, char *out, size_t out_len)
The file an entry lives in, whether or not it exists.
void n_disk_cache_close(N_DISK_CACHE **cache)
Forget a cache.
int n_disk_cache_put(const N_DISK_CACHE *cache, const void *key, size_t key_len, const char *ext, const void *data, size_t len)
Store an entry, replacing any under the same key and extension.
int n_disk_cache_prune_group(const N_DISK_CACHE *const *caches, int count, uint64_t max_bytes)
n_disk_cache_prune() over several caches that share one budget.
int n_disk_cache_prune(const N_DISK_CACHE *cache, uint64_t max_bytes)
Remove least recently used entries until the rest fit a budget.
int n_disk_cache_remove(const N_DISK_CACHE *cache, const void *key, size_t key_len, const char *ext)
Remove one entry, for a caller that found it unreadable.
int n_disk_cache_expire(const N_DISK_CACHE *cache, int64_t max_age_seconds)
Remove every entry unused for longer than an age.
int n_disk_cache_size(const N_DISK_CACHE *cache, uint64_t *total)
How many bytes the cache's entries take.
N_DISK_CACHE * n_disk_cache_open(const char *dir)
Use a directory as a cache.
Common headers and low-level functions & define.
char * dir
the directory, without a trailing separator
a cache: only where it is