libcommonc++  0.7
DynamicCache.h++
Go to the documentation of this file.
1 /* ---------------------------------------------------------------------------
2  commonc++ - A C++ Common Class Library
3  Copyright (C) 2005-2014 Mark A Lindner
4 
5  This file is part of commonc++.
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Library General Public
9  License as published by the Free Software Foundation; either
10  version 2 of the License, or (at your option) any later version.
11 
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Library General Public License for more details.
16 
17  You should have received a copy of the GNU Library General Public
18  License along with this library; if not, write to the Free
19  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  ---------------------------------------------------------------------------
21 */
22 
23 #ifndef __ccxx_DynamicCache_hxx
24 #define __ccxx_DynamicCache_hxx
25 
27 
28 namespace ccxx {
29 
46 template<typename K, typename T> class DynamicCache
47  : public AbstractCache<K, T>
48 {
49  public:
50 
57  DynamicCache(uint_t maxSize);
58 
62  virtual ~DynamicCache();
63 
70  void put(K key, T* item);
71 
81  virtual T* get(const K& key);
82 
91  T* take(const K& key);
92 
100  bool remove(const K& key);
101 
102  protected:
103 
114  virtual T* loadItem(const K& key);
115 
116  private:
117 
118  typedef typename AbstractCache<K, T>::Link Link;
119  typedef typename AbstractCache<K, T>::MapType MapType;
120 };
121 
122 #include <commonc++/DynamicCacheImpl.h++>
123 
124 } // namespace ccxx
125 
126 #endif // __ccxx_DynamicCache_hxx
T * take(const K &key)
Remove an item from the cache, and return the item.
unsigned int uint_t
An alias for unsigned int.
Definition: Integers.h++:74
virtual T * loadItem(const K &key)
Called by get() when the cache does not contain an item with the requested key.
An abstract base class for a general-purpose LRU-cache with a maximum capacity.
Definition: AbstractCache.h++:46
DynamicCache(uint_t maxSize)
Construct a new DynamicCache with the given maximum size.
void put(K key, T *item)
Put an item in the cache.
Definition: AllocationMap.c++:25
An LRU cache implementation in which cache objects are deleted when they are removed from the cache...
Definition: DynamicCache.h++:46
virtual ~DynamicCache()
Destructor.