1 /* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements. See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
24 #include "mod_cache.h"
28 * @brief Cache Cache Functions
32 * @defgroup Cache_cache Cache Functions
36 /** ADT for the cache */
37 typedef struct cache_cache_t cache_cache_t;
39 /** callback to increment the frequency of a item */
40 typedef void cache_cache_inc_frequency(void*a);
41 /** callback to get the size of a item */
42 typedef apr_size_t cache_cache_get_size(void*a);
43 /** callback to get the key of a item */
44 typedef const char* cache_cache_get_key(void *a);
45 /** callback to free an entry */
46 typedef void cache_cache_free(void *a);
49 * initialize the cache ADT
50 * @param max_entries the number of entries in the cache
51 * @param max_size the size of the cache
52 * @param get_pri callback to get a priority of a entry
53 * @param set_pri callback to set a priority of a entry
54 * @param get_pos callback to get the position of a entry in the cache
55 * @param set_pos callback to set the position of a entry in the cache
56 * @param inc_entry callback to increment the frequency of a entry
57 * @param size_entry callback to get the size of a entry
58 * @param key_entry callback to get the key of a entry
59 * @param free_entry callback to free an entry
61 CACHE_DECLARE(cache_cache_t *)cache_init(int max_entries,
63 cache_pqueue_get_priority get_pri,
64 cache_pqueue_set_priority set_pri,
65 cache_pqueue_getpos get_pos,
66 cache_pqueue_setpos set_pos,
67 cache_cache_inc_frequency *inc_entry,
68 cache_cache_get_size *size_entry,
69 cache_cache_get_key *key_entry,
70 cache_cache_free *free_entry);
76 CACHE_DECLARE(void) cache_free(cache_cache_t *c);
78 * find a entry in the cache, incrementing the frequency if found
82 CACHE_DECLARE(void*) cache_find(cache_cache_t* c, const char *key);
84 * insert a entry into the cache
86 * @param entry the entry
88 CACHE_DECLARE(void) cache_update(cache_cache_t* c, void *entry);
90 * insert a entry into the cache
92 * @param entry the entry
94 CACHE_DECLARE(void) cache_insert(cache_cache_t* c, void *entry);
96 * pop the lowest priority item off
98 * @returns the entry or NULL
100 CACHE_DECLARE(void *)cache_pop(cache_cache_t* c);
102 * remove an item from the cache
104 * @param entry the actual entry (from a find)
106 CACHE_DECLARE(apr_status_t) cache_remove(cache_cache_t* c, void *entry);
112 #endif /* !CACHE_CACHE_H */