cache_cache.h revision 0a649f5f00c3fca1b5ed74d3044313e9d69dd60b
a78048ccbdb6256da15e6b0e7e95355e480c2301nd/* Licensed to the Apache Software Foundation (ASF) under one or more
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * contributor license agreements. See the NOTICE file distributed with
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * this work for additional information regarding copyright ownership.
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * The ASF licenses this file to You under the Apache License, Version 2.0
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * (the "License"); you may not use this file except in compliance with
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * the License. You may obtain a copy of the License at
a78048ccbdb6256da15e6b0e7e95355e480c2301nd *
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * http://www.apache.org/licenses/LICENSE-2.0
a78048ccbdb6256da15e6b0e7e95355e480c2301nd *
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * Unless required by applicable law or agreed to in writing, software
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * distributed under the License is distributed on an "AS IS" BASIS,
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * See the License for the specific language governing permissions and
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * limitations under the License.
a78048ccbdb6256da15e6b0e7e95355e480c2301nd */
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301nd/**
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * @file cache_cache.h
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * @brief Cache Cache Functions
a78048ccbdb6256da15e6b0e7e95355e480c2301nd *
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * @defgroup Cache_cache Cache Functions
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * @ingroup MOD_CACHE
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * @{
a78048ccbdb6256da15e6b0e7e95355e480c2301nd */
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301nd#ifndef CACHE_CACHE_H
a78048ccbdb6256da15e6b0e7e95355e480c2301nd#define CACHE_CACHE_H
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301nd#ifdef __cplusplus
a78048ccbdb6256da15e6b0e7e95355e480c2301ndextern "C" {
a78048ccbdb6256da15e6b0e7e95355e480c2301nd#endif
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301nd#include "mod_cache.h"
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301nd/** ADT for the cache */
a78048ccbdb6256da15e6b0e7e95355e480c2301ndtypedef struct cache_cache_t cache_cache_t;
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301nd/** callback to increment the frequency of a item */
a78048ccbdb6256da15e6b0e7e95355e480c2301ndtypedef void cache_cache_inc_frequency(void*a);
a78048ccbdb6256da15e6b0e7e95355e480c2301nd/** callback to get the size of a item */
a78048ccbdb6256da15e6b0e7e95355e480c2301ndtypedef apr_size_t cache_cache_get_size(void*a);
a78048ccbdb6256da15e6b0e7e95355e480c2301nd/** callback to get the key of a item */
a78048ccbdb6256da15e6b0e7e95355e480c2301ndtypedef const char* cache_cache_get_key(void *a);
a78048ccbdb6256da15e6b0e7e95355e480c2301nd/** callback to free an entry */
a78048ccbdb6256da15e6b0e7e95355e480c2301ndtypedef void cache_cache_free(void *a);
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301nd/**
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * initialize the cache ADT
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * @param max_entries the number of entries in the cache
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * @param max_size the size of the cache
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * @param get_pri callback to get a priority of a entry
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * @param set_pri callback to set a priority of a entry
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * @param get_pos callback to get the position of a entry in the cache
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * @param set_pos callback to set the position of a entry in the cache
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * @param inc_entry callback to increment the frequency of a entry
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * @param size_entry callback to get the size of a entry
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * @param key_entry callback to get the key of a entry
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * @param free_entry callback to free an entry
a78048ccbdb6256da15e6b0e7e95355e480c2301nd */
a78048ccbdb6256da15e6b0e7e95355e480c2301ndcache_cache_t* cache_init(int max_entries,
a78048ccbdb6256da15e6b0e7e95355e480c2301nd apr_size_t max_size,
a78048ccbdb6256da15e6b0e7e95355e480c2301nd cache_pqueue_get_priority get_pri,
a78048ccbdb6256da15e6b0e7e95355e480c2301nd cache_pqueue_set_priority set_pri,
a78048ccbdb6256da15e6b0e7e95355e480c2301nd cache_pqueue_getpos get_pos,
a78048ccbdb6256da15e6b0e7e95355e480c2301nd cache_pqueue_setpos set_pos,
a78048ccbdb6256da15e6b0e7e95355e480c2301nd cache_cache_inc_frequency *inc_entry,
a78048ccbdb6256da15e6b0e7e95355e480c2301nd cache_cache_get_size *size_entry,
a78048ccbdb6256da15e6b0e7e95355e480c2301nd cache_cache_get_key *key_entry,
a78048ccbdb6256da15e6b0e7e95355e480c2301nd cache_cache_free *free_entry);
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301nd/**
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * free up the cache
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * @param c the cache
a78048ccbdb6256da15e6b0e7e95355e480c2301nd */
a78048ccbdb6256da15e6b0e7e95355e480c2301ndvoid cache_free(cache_cache_t *c);
a78048ccbdb6256da15e6b0e7e95355e480c2301nd/**
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * find a entry in the cache, incrementing the frequency if found
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * @param c the cache
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * @param key the key
a78048ccbdb6256da15e6b0e7e95355e480c2301nd */
a78048ccbdb6256da15e6b0e7e95355e480c2301ndvoid* cache_find(cache_cache_t* c, const char *key);
a78048ccbdb6256da15e6b0e7e95355e480c2301nd/**
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * insert a entry into the cache
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * @param c the cache
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * @param entry the entry
a78048ccbdb6256da15e6b0e7e95355e480c2301nd */
a78048ccbdb6256da15e6b0e7e95355e480c2301ndvoid cache_update(cache_cache_t* c, void *entry);
a78048ccbdb6256da15e6b0e7e95355e480c2301nd/**
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * insert a entry into the cache
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * @param c the cache
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * @param entry the entry
a78048ccbdb6256da15e6b0e7e95355e480c2301nd */
a78048ccbdb6256da15e6b0e7e95355e480c2301ndvoid cache_insert(cache_cache_t* c, void *entry);
a78048ccbdb6256da15e6b0e7e95355e480c2301nd/**
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * pop the lowest priority item off
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * @param c the cache
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * @returns the entry or NULL
a78048ccbdb6256da15e6b0e7e95355e480c2301nd */
a78048ccbdb6256da15e6b0e7e95355e480c2301ndvoid* cache_pop(cache_cache_t* c);
a78048ccbdb6256da15e6b0e7e95355e480c2301nd/**
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * remove an item from the cache
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * @param c the cache
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * @param entry the actual entry (from a find)
a78048ccbdb6256da15e6b0e7e95355e480c2301nd */
a78048ccbdb6256da15e6b0e7e95355e480c2301ndapr_status_t cache_remove(cache_cache_t* c, void *entry);
a78048ccbdb6256da15e6b0e7e95355e480c2301nd#ifdef __cplusplus
a78048ccbdb6256da15e6b0e7e95355e480c2301nd}
a78048ccbdb6256da15e6b0e7e95355e480c2301nd#endif
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301nd#endif /* !CACHE_CACHE_H */
a78048ccbdb6256da15e6b0e7e95355e480c2301nd/** @} */
a78048ccbdb6256da15e6b0e7e95355e480c2301nd