mirror of
https://github.com/glest/glest-source.git
synced 2025-02-25 04:02:30 +01:00
Some cleanup related to Cache Management
This commit is contained in:
parent
33084f8dbe
commit
ff592be457
@ -31,7 +31,6 @@ class CacheManager
|
||||
{
|
||||
protected:
|
||||
static Mutex mutexCache;
|
||||
static std::map<std::string, bool> masterCacheList;
|
||||
|
||||
typedef enum {
|
||||
cacheItemGet,
|
||||
@ -40,13 +39,23 @@ protected:
|
||||
|
||||
template <typename T>
|
||||
static T & manageCachedItem(string cacheKey, T *value,CacheAccessorType accessor) {
|
||||
// Here is the actual type-safe instantiation
|
||||
static std::map<string, T > itemCache;
|
||||
|
||||
if(accessor == cacheItemSet) {
|
||||
if(value == NULL) {
|
||||
throw runtime_error("Unexpected NULL object setting cache value!");
|
||||
try {
|
||||
mutexCache.p();
|
||||
if(itemCache.find(cacheKey) != itemCache.end()) {
|
||||
itemCache.erase(cacheKey);
|
||||
}
|
||||
mutexCache.v();
|
||||
}
|
||||
catch(const std::exception &ex) {
|
||||
mutexCache.v();
|
||||
throw runtime_error(ex.what());
|
||||
}
|
||||
|
||||
}
|
||||
masterCacheList[cacheKey] = true;
|
||||
try {
|
||||
mutexCache.p();
|
||||
itemCache[cacheKey] = *value;
|
||||
@ -57,17 +66,14 @@ protected:
|
||||
throw runtime_error(ex.what());
|
||||
}
|
||||
}
|
||||
// If this is the first access we return a default object of the type
|
||||
return itemCache[cacheKey];
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
CacheManager() {
|
||||
|
||||
}
|
||||
~CacheManager() {
|
||||
|
||||
}
|
||||
CacheManager() { }
|
||||
~CacheManager() { }
|
||||
|
||||
template <typename T>
|
||||
static void setCachedItem(string cacheKey, const T value) {
|
||||
@ -77,6 +83,10 @@ public:
|
||||
static T & getCachedItem(string cacheKey) {
|
||||
return manageCachedItem<T>(cacheKey,NULL,cacheItemGet);
|
||||
}
|
||||
template <typename T>
|
||||
static void clearCachedItem(string cacheKey) {
|
||||
return manageCachedItem<T>(cacheKey,NULL,cacheItemSet);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
@ -14,6 +14,5 @@
|
||||
namespace Shared { namespace PlatformCommon {
|
||||
|
||||
Mutex CacheManager::mutexCache;
|
||||
std::map<string, bool> CacheManager::masterCacheList;
|
||||
|
||||
}}//end namespace
|
||||
|
Loading…
x
Reference in New Issue
Block a user