| 1 | /* |
| 2 | * This file is part of DisOrder |
| 3 | * Copyright (C) 2006-2008 Richard Kettlewell |
| 4 | * |
| 5 | * This program is free software: you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation, either version 3 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | */ |
| 18 | /** @file lib/cache.h |
| 19 | * @brief Object caching |
| 20 | * |
| 21 | * There is a single cache for the whole process. Objects of different types |
| 22 | * are distinguished. Objects might be thrown out of the cache at any point. |
| 23 | */ |
| 24 | |
| 25 | #ifndef CACHE_H |
| 26 | #define CACHE_H |
| 27 | |
| 28 | /* Defines a cache mapping keys to typed data items */ |
| 29 | |
| 30 | /** @brief Type of a cache object */ |
| 31 | struct cache_type { |
| 32 | /** @brief Lifetime for objects of this type (seconds) */ |
| 33 | int lifetime; |
| 34 | }; |
| 35 | |
| 36 | void cache_put(const struct cache_type *type, |
| 37 | const char *key, const void *value); |
| 38 | /* Inserts KEY into the cache with value VALUE. If KEY is already |
| 39 | * present it is overwritten. */ |
| 40 | |
| 41 | const void *cache_get(const struct cache_type *type, const char *key); |
| 42 | /* Get a value from the cache. */ |
| 43 | |
| 44 | void cache_expire(void); |
| 45 | /* Expire values from the cache */ |
| 46 | |
| 47 | void cache_clean(const struct cache_type *type); |
| 48 | /* Clean all elements of a particular type, or all elements if TYPE=0 */ |
| 49 | |
| 50 | size_t cache_count(void); |
| 51 | /* Return the size of the cache */ |
| 52 | |
| 53 | #endif /* CACHE_H */ |
| 54 | |
| 55 | /* |
| 56 | Local Variables: |
| 57 | c-basic-offset:2 |
| 58 | comment-column:40 |
| 59 | fill-column:79 |
| 60 | indent-tabs-mode:nil |
| 61 | End: |
| 62 | */ |