42 #include "BESInternalError.h"
45 #include "TheBESKeys.h"
47 #include "GatewayCache.h"
50 #define AT_EXIT(x) atexit((x))
55 using namespace gateway;
58 bool GatewayCache::d_enabled =
true;
60 const string GatewayCache::DIR_KEY =
"Gateway.Cache.dir";
61 const string GatewayCache::PREFIX_KEY =
"Gateway.Cache.prefix";
62 const string GatewayCache::SIZE_KEY =
"Gateway.Cache.size";
64 unsigned long GatewayCache::getCacheSizeFromConfig()
69 unsigned long size_in_megabytes = 0;
72 std::istringstream iss(size);
73 iss >> size_in_megabytes;
76 string msg =
"GatewayCache - The BES Key " + SIZE_KEY +
" is not set.";
77 BESDEBUG(
"cache", msg << endl);
80 return size_in_megabytes;
83 string GatewayCache::getCacheDirFromConfig()
90 string msg =
"GatewayCache - The BES Key " + DIR_KEY +
" is not set.";
91 BESDEBUG(
"cache", msg << endl);
98 string GatewayCache::getCachePrefixFromConfig()
107 string msg =
"GatewayCache - The BES Key " + PREFIX_KEY +
" is not set.";
108 BESDEBUG(
"cache", msg << endl);
115 GatewayCache::GatewayCache()
117 BESDEBUG(
"cache",
"GatewayCache::GatewayCache() - BEGIN" << endl);
119 string cacheDir = getCacheDirFromConfig();
120 string cachePrefix = getCachePrefixFromConfig();
121 unsigned long cacheSizeMbytes = getCacheSizeFromConfig();
124 "GatewayCache() - Cache configuration params: " << cacheDir <<
", " << cachePrefix <<
", " << cacheSizeMbytes << endl);
126 initialize(cacheDir, cachePrefix, cacheSizeMbytes);
128 BESDEBUG(
"cache",
"GatewayCache::GatewayCache() - END" << endl);
131 GatewayCache::GatewayCache(
const string &cache_dir,
const string &prefix,
unsigned long long size)
133 BESDEBUG(
"cache",
"GatewayCache::GatewayCache() - BEGIN" << endl);
137 BESDEBUG(
"cache",
"GatewayCache::GatewayCache() - END" << endl);
143 if (d_enabled && d_instance == 0) {
145 d_instance =
new GatewayCache(cache_dir, cache_file_prefix, max_cache_size);
150 BESDEBUG(
"cache",
"GatewayCache::"<<__func__ <<
"() - " <<
"Cache is DISABLED"<< endl);
153 AT_EXIT(delete_instance);
155 BESDEBUG(
"cache",
"GatewayCache::"<<__func__ <<
"() - " <<
"Cache is ENABLED"<< endl);
169 if (d_enabled && d_instance == 0) {
176 BESDEBUG(
"cache",
"GatewayCache::"<<__func__ <<
"() - " <<
"Cache is DISABLED"<< endl);
179 AT_EXIT(delete_instance);
181 BESDEBUG(
"cache",
"GatewayCache::" << __func__ <<
"() - " <<
"Cache is ENABLED"<< endl);
186 "[ERROR] GatewayCache::get_instance(): Failed to obtain cache! msg: " << bie.
get_message() << endl);