cacheplcs.h revision 158115
1158115Sume/*- 2158115Sume * Copyright (c) 2005 Michael Bushkov <bushman@rsu.ru> 3158115Sume * All rights reserved. 4158115Sume * 5158115Sume * Redistribution and use in source and binary forms, with or without 6158115Sume * modification, are permitted provided that the following conditions 7158115Sume * are met: 8158115Sume * 1. Redistributions of source code must retain the above copyright 9158115Sume * notice, this list of conditions and the following disclaimer. 10158115Sume * 2. Redistributions in binary form must reproduce the above copyright 11158115Sume * notice, this list of conditions and the following disclaimer in the 12158115Sume * documentation and/or other materials provided with the distribution. 13158115Sume * 14158115Sume * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15158115Sume * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16158115Sume * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17158115Sume * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18158115Sume * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19158115Sume * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20158115Sume * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21158115Sume * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22158115Sume * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23158115Sume * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24158115Sume * SUCH DAMAGE. 25158115Sume * 26158115Sume * $FreeBSD: head/usr.sbin/nscd/cacheplcs.h 158115 2006-04-28 12:03:38Z ume $ 27158115Sume */ 28158115Sume 29158115Sume#ifndef __CACHED_CACHEPLCS_H__ 30158115Sume#define __CACHED_CACHEPLCS_H__ 31158115Sume 32158115Sume#include <sys/queue.h> 33158115Sume#include <sys/time.h> 34158115Sume#include <stdlib.h> 35158115Sume 36158115Sume/* common policy definitions */ 37158115Sume#define CACHELIB_MAX_FREQUENCY 100 38158115Sume 39158115Sume/* 40158115Sume * cache_policy_item_ represents some abstract cache element in the policy 41158115Sume * queue. connected_item pointers to the corresponding cache_policy_item_ in 42158115Sume * another policy queue. 43158115Sume */ 44158115Sumestruct cache_policy_item_ 45158115Sume{ 46158115Sume char *key; 47158115Sume size_t key_size; 48158115Sume 49158115Sume size_t request_count; 50158115Sume struct timeval last_request_time; 51158115Sume struct timeval creation_time; 52158115Sume 53158115Sume struct cache_policy_item_ *connected_item; 54158115Sume}; 55158115Sume 56158115Sume/* 57158115Sume * cache_policy_ represents an abstract policy queue. It can be customized by 58158115Sume * setting appropriate function pointers 59158115Sume */ 60158115Sumestruct cache_policy_ 61158115Sume{ 62158115Sume struct cache_policy_item_* (*create_item_func)(); 63158115Sume void (*destroy_item_func)(struct cache_policy_item_ *); 64158115Sume 65158115Sume void (*add_item_func)(struct cache_policy_ *, 66158115Sume struct cache_policy_item_ *); 67158115Sume void (*remove_item_func)(struct cache_policy_ *, 68158115Sume struct cache_policy_item_ *); 69158115Sume void (*update_item_func)(struct cache_policy_ *, 70158115Sume struct cache_policy_item_ *); 71158115Sume 72158115Sume struct cache_policy_item_ *(*get_first_item_func)( 73158115Sume struct cache_policy_ *); 74158115Sume struct cache_policy_item_ *(*get_last_item_func)( 75158115Sume struct cache_policy_ *); 76158115Sume struct cache_policy_item_ *(*get_next_item_func)( 77158115Sume struct cache_policy_ *, struct cache_policy_item_ *); 78158115Sume struct cache_policy_item_ *(*get_prev_item_func)( 79158115Sume struct cache_policy_ *, struct cache_policy_item_ *); 80158115Sume}; 81158115Sume 82158115Sume/* 83158115Sume * LFU cache policy item "inherited" from cache_policy_item_ structure 84158115Sume */ 85158115Sumestruct cache_lfu_policy_item_ 86158115Sume{ 87158115Sume struct cache_policy_item_ parent_data; 88158115Sume int frequency; 89158115Sume 90158115Sume TAILQ_ENTRY(cache_lfu_policy_item_) entries; 91158115Sume}; 92158115Sume 93158115SumeTAILQ_HEAD(cache_lfu_policy_group_, cache_lfu_policy_item_); 94158115Sume 95158115Sume/* 96158115Sume * LFU policy queue "inherited" from cache_policy_. 97158115Sume */ 98158115Sumestruct cache_lfu_policy_ 99158115Sume{ 100158115Sume struct cache_policy_ parent_data; 101158115Sume struct cache_lfu_policy_group_ groups[CACHELIB_MAX_FREQUENCY]; 102158115Sume}; 103158115Sume 104158115Sume/* 105158115Sume * LRU and FIFO policies item "inherited" from cache_policy_item_ 106158115Sume */ 107158115Sumestruct cache_queue_policy_item_ 108158115Sume{ 109158115Sume struct cache_policy_item_ parent_data; 110158115Sume TAILQ_ENTRY(cache_queue_policy_item_) entries; 111158115Sume}; 112158115Sume 113158115Sume/* 114158115Sume * LRU and FIFO policies "inherited" from cache_policy_ 115158115Sume */ 116158115Sumestruct cache_queue_policy_ 117158115Sume{ 118158115Sume struct cache_policy_ parent_data; 119158115Sume TAILQ_HEAD(cache_queue_policy_head_, cache_queue_policy_item_) head; 120158115Sume}; 121158115Sume 122158115Sumetypedef struct cache_queue_policy_ cache_fifo_policy_; 123158115Sumetypedef struct cache_queue_policy_ cache_lru_policy_; 124158115Sume 125158115Sume/* fifo policy routines */ 126158115Sumeextern struct cache_policy_ *init_cache_fifo_policy(); 127158115Sumeextern void destroy_cache_fifo_policy(struct cache_policy_ *); 128158115Sume 129158115Sume/* lru policy routines */ 130158115Sumeextern struct cache_policy_ *init_cache_lru_policy(); 131158115Sumeextern void destroy_cache_lru_policy(struct cache_policy_ *); 132158115Sume 133158115Sume/* lfu policy routines */ 134158115Sumeextern struct cache_policy_ *init_cache_lfu_policy(); 135158115Sumeextern void destroy_cache_lfu_policy(struct cache_policy_ *); 136158115Sume 137158115Sume#endif 138