cacheplcs.h revision 194087
11573Srgrimes/*- 21573Srgrimes * Copyright (c) 2005 Michael Bushkov <bushman@rsu.ru> 31573Srgrimes * All rights reserved. 41573Srgrimes * 51573Srgrimes * Redistribution and use in source and binary forms, with or without 61573Srgrimes * modification, are permitted provided that the following conditions 71573Srgrimes * are met: 81573Srgrimes * 1. Redistributions of source code must retain the above copyright 91573Srgrimes * notice, this list of conditions and the following disclaimer. 101573Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 111573Srgrimes * notice, this list of conditions and the following disclaimer in the 121573Srgrimes * documentation and/or other materials provided with the distribution. 131573Srgrimes * 141573Srgrimes * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 151573Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 161573Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 171573Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 181573Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 191573Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 201573Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 211573Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 221573Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 231573Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 241573Srgrimes * SUCH DAMAGE. 251573Srgrimes * 261573Srgrimes * $FreeBSD: head/usr.sbin/nscd/cacheplcs.h 194087 2009-06-12 23:39:05Z des $ 271573Srgrimes */ 2823660Speter 2950476Speter#ifndef __NSCD_CACHEPLCS_H__ 301573Srgrimes#define __NSCD_CACHEPLCS_H__ 31281729Spluknet 321573Srgrimes#include <sys/queue.h> 3379531Sru#include <sys/time.h> 341573Srgrimes#include <stdlib.h> 351573Srgrimes 36127060Stjr/* common policy definitions */ 371573Srgrimes#define CACHELIB_MAX_FREQUENCY 100 38107788Sru 3959460Sphantom/* 4059460Sphantom * cache_policy_item_ represents some abstract cache element in the policy 411573Srgrimes * queue. connected_item pointers to the corresponding cache_policy_item_ in 4284306Sru * another policy queue. 4384306Sru */ 441573Srgrimesstruct cache_policy_item_ 4530963Sjmg{ 461573Srgrimes char *key; 471573Srgrimes size_t key_size; 48127060Stjr 49127060Stjr size_t request_count; 50127060Stjr struct timeval last_request_time; 511573Srgrimes struct timeval creation_time; 521573Srgrimes 531573Srgrimes struct cache_policy_item_ *connected_item; 54108028Sru}; 55107788Sru 561573Srgrimes/* 57108040Sru * cache_policy_ represents an abstract policy queue. It can be customized by 581573Srgrimes * setting appropriate function pointers 59108040Sru */ 60107788Srustruct cache_policy_ 611573Srgrimes{ 62108040Sru struct cache_policy_item_* (*create_item_func)(void); 631573Srgrimes void (*destroy_item_func)(struct cache_policy_item_ *); 64108040Sru 651573Srgrimes void (*add_item_func)(struct cache_policy_ *, 66108040Sru struct cache_policy_item_ *); 671573Srgrimes void (*remove_item_func)(struct cache_policy_ *, 68107788Sru struct cache_policy_item_ *); 691573Srgrimes void (*update_item_func)(struct cache_policy_ *, 70108040Sru struct cache_policy_item_ *); 711573Srgrimes 72108040Sru struct cache_policy_item_ *(*get_first_item_func)( 731573Srgrimes struct cache_policy_ *); 741573Srgrimes struct cache_policy_item_ *(*get_last_item_func)( 75107788Sru struct cache_policy_ *); 761573Srgrimes struct cache_policy_item_ *(*get_next_item_func)( 77127060Stjr struct cache_policy_ *, struct cache_policy_item_ *); 78127060Stjr struct cache_policy_item_ *(*get_prev_item_func)( 79127060Stjr struct cache_policy_ *, struct cache_policy_item_ *); 80127060Stjr}; 81131365Sru 82127060Stjr/* 83127060Stjr * LFU cache policy item "inherited" from cache_policy_item_ structure 84127060Stjr */ 85127060Stjrstruct cache_lfu_policy_item_ 86127060Stjr{ 87127060Stjr struct cache_policy_item_ parent_data; 88131365Sru int frequency; 89281729Spluknet 90127060Stjr TAILQ_ENTRY(cache_lfu_policy_item_) entries; 91131365Sru}; 92127060Stjr 93131365SruTAILQ_HEAD(cache_lfu_policy_group_, cache_lfu_policy_item_); 94127060Stjr 95127060Stjr/* 96131365Sru * LFU policy queue "inherited" from cache_policy_. 97127060Stjr */ 98131365Srustruct cache_lfu_policy_ 99127060Stjr{ 100127060Stjr struct cache_policy_ parent_data; 101127060Stjr struct cache_lfu_policy_group_ groups[CACHELIB_MAX_FREQUENCY]; 102127060Stjr}; 103109186Sjoerg 104109186Sjoerg/* 105111285Sru * LRU and FIFO policies item "inherited" from cache_policy_item_ 106111285Sru */ 107111285Srustruct cache_queue_policy_item_ 108111285Sru{ 109111285Sru struct cache_policy_item_ parent_data; 110208586Scperciva TAILQ_ENTRY(cache_queue_policy_item_) entries; 111109186Sjoerg}; 1121573Srgrimes 113108040Sru/* 1141573Srgrimes * LRU and FIFO policies "inherited" from cache_policy_ 115107788Sru */ 1161573Srgrimesstruct cache_queue_policy_ 1171573Srgrimes{ 118107788Sru struct cache_policy_ parent_data; 119109186Sjoerg TAILQ_HEAD(cache_queue_policy_head_, cache_queue_policy_item_) head; 12079754Sdd}; 121107788Sru 1221573Srgrimestypedef struct cache_queue_policy_ cache_fifo_policy_; 123107788Srutypedef struct cache_queue_policy_ cache_lru_policy_; 1241573Srgrimes 1251573Srgrimes/* fifo policy routines */ 126109186Sjoergextern struct cache_policy_ *init_cache_fifo_policy(void); 12719595Sobrienextern void destroy_cache_fifo_policy(struct cache_policy_ *); 12819595Sobrien 129133654Sroam/* lru policy routines */ 130133654Sroamextern struct cache_policy_ *init_cache_lru_policy(void); 131133654Sroamextern void destroy_cache_lru_policy(struct cache_policy_ *); 132133654Sroam 133133654Sroam/* lfu policy routines */ 13431144Sjulianextern struct cache_policy_ *init_cache_lfu_policy(void); 13531144Sjulianextern void destroy_cache_lfu_policy(struct cache_policy_ *); 136117089Siedowse 137117089Siedowse#endif 138117089Siedowse