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.
19 * @brief Cache Cache Functions
21 * @defgroup Cache_cache Cache Functions
33 #include "mod_cache.h"
35 /** ADT for the cache */
36 typedef struct cache_cache_t cache_cache_t;
38 /** callback to increment the frequency of a item */
39 typedef void cache_cache_inc_frequency(void*a);
40 /** callback to get the size of a item */
41 typedef apr_size_t cache_cache_get_size(void*a);
42 /** callback to get the key of a item */
43 typedef const char* cache_cache_get_key(void *a);
44 /** callback to free an entry */
45 typedef void cache_cache_free(void *a);
48 * initialize the cache ADT
49 * @param max_entries the number of entries in the cache
50 * @param max_size the size of the cache
51 * @param get_pri callback to get a priority of a entry
52 * @param set_pri callback to set a priority of a entry
53 * @param get_pos callback to get the position of a entry in the cache
54 * @param set_pos callback to set the position of a entry in the cache
55 * @param inc_entry callback to increment the frequency of a entry
56 * @param size_entry callback to get the size of a entry
57 * @param key_entry callback to get the key of a entry
58 * @param free_entry callback to free an entry
60 cache_cache_t* cache_init(int max_entries,
62 cache_pqueue_get_priority get_pri,
63 cache_pqueue_set_priority set_pri,
64 cache_pqueue_getpos get_pos,
65 cache_pqueue_setpos set_pos,
66 cache_cache_inc_frequency *inc_entry,
67 cache_cache_get_size *size_entry,
68 cache_cache_get_key *key_entry,
69 cache_cache_free *free_entry);
75 void cache_free(cache_cache_t *c);
77 * find a entry in the cache, incrementing the frequency if found
81 void* cache_find(cache_cache_t* c, const char *key);
83 * insert a entry into the cache
85 * @param entry the entry
87 void cache_update(cache_cache_t* c, void *entry);
89 * insert a entry into the cache
91 * @param entry the entry
93 void cache_insert(cache_cache_t* c, void *entry);
95 * pop the lowest priority item off
97 * @returns the entry or NULL
99 void* cache_pop(cache_cache_t* c);
101 * remove an item from the cache
103 * @param entry the actual entry (from a find)
105 apr_status_t cache_remove(cache_cache_t* c, void *entry);
110 #endif /* !CACHE_CACHE_H */