CernVM-FS  2.9.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
lru.h File Reference
#include <stdint.h>
#include <algorithm>
#include <cassert>
#include <cstring>
#include <functional>
#include <map>
#include <string>
#include "atomic.h"
#include "platform.h"
#include "smallhash.h"
#include "smalloc.h"
#include "statistics.h"
#include "util/single_copy.h"
Include dependency graph for lru.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  lru::Counters
 
class  lru::LruCache< Key, Value >
 
class  lru::LruCache< Key, Value >::ListEntry< T >
 
class  lru::LruCache< Key, Value >::ListEntryHead< T >
 
class  lru::LruCache< Key, Value >::ListEntryContent< T >
 
class  lru::LruCache< Key, Value >::MemoryAllocator< M >
 
struct  lru::LruCache< Key, Value >::CacheEntry
 
class  lru::LruCache< Key, Value >::MemoryAllocator< M >
 
class  lru::LruCache< Key, Value >::ListEntry< T >
 
class  lru::LruCache< Key, Value >::ListEntryContent< T >
 
class  lru::LruCache< Key, Value >::ListEntryHead< T >
 

Namespaces

 lru
 

Macros

#define LRU_CACHE_THREAD_SAFE
 

Macro Definition Documentation

#define LRU_CACHE_THREAD_SAFE

This file is part of the CernVM File System.

This class provides an Least Recently Used (LRU) cache for arbitrary data It stores Key-Value pairs of arbitrary data types in a hash table and automatically deletes the entries which are least touched in the last time to prevent the structure from growing beyond a given maximal cache size. The cache uses a hand crafted memory allocator to use memory efficiently

Hash functions have to be provided. They should return an equal distribution of keys in uint32_t. In addition, a special key has to be provided that is used to mark "empty" elements in the hash table.

The cache size has to be a multiply of 64.

usage: // 100 entries, -1 special key LruCache<int, string> cache(100, -1, hasher_int);

// Inserting some stuff cache.insert(42, "fourtytwo"); cache.insert(2, "small prime number"); cache.insert(1337, "leet");

// Trying to retrieve a value int result; if (cache.lookup(21, result)) { cout << "cache hit: " << result << endl; } else { cout << "cache miss" << endl; }

cache.drop(); // Empty the cache

Definition at line 40 of file lru.h.