00001 #ifndef HLBR_CACHE_H 00002 #define HLBR_CACHE_H 00003 00004 #include "../config.h" 00005 #include "hlbr.h" 00006 00007 #define CACHE_MAX_KEYS 256 00008 #define CACHE_MAX_ITEMS_PER_KEY 64 00009 #define CACHE_NONE -1 00010 00011 typedef struct cache_item{ 00012 unsigned char* Data; 00013 unsigned int DataLen; 00014 }CacheItem; 00015 00016 typedef struct cache_items{ 00017 unsigned char* Key; 00018 int KeyLen; 00019 00020 CacheItem Items[CACHE_MAX_ITEMS_PER_KEY]; 00021 unsigned int NumItems; 00022 00023 long LastTime; 00024 }CacheItems; 00025 00026 typedef struct cache{ 00027 CacheItems Keys[CACHE_MAX_KEYS]; 00028 unsigned int NumKeys; 00029 00030 long TimeoutLen; 00031 } Cache; 00032 00033 Cache* InitCache(int TimeoutLen); 00034 int CacheAdd(Cache* c, unsigned char* Key, int KeyLen, unsigned char* Data, int DataLen, int Now); 00035 int CacheDelKey(Cache* c, unsigned char* Key, int KeyLen, int Now); 00036 CacheItems* CacheGet(Cache* c, unsigned char* Key, int KeyLen, int Now); 00037 void DestroyCache(Cache* c); 00038 00039 00040 00041 #endif