Added clear method to FileCache.

This commit is contained in:
Relintai 2022-02-04 22:03:22 +01:00
parent 60ed46b5e6
commit 60e7dfe7e9
2 changed files with 20 additions and 1 deletions

View File

@ -101,6 +101,24 @@ void FileCache::set_cached_body(const String &path, const String &body) {
cache_mutex.unlock(); cache_mutex.unlock();
} }
void FileCache::clear() {
cache_mutex.lock();
registered_files.clear();
for (std::map<String, CacheEntry *>::iterator E = cache_map.begin(); E != cache_map.end(); E++) {
CacheEntry * ce = E->second;
if (ce) {
delete ce;
}
}
cache_map.clear();
cache_mutex.unlock();
}
FileCache::FileCache(bool singleton) { FileCache::FileCache(bool singleton) {
if (singleton) { if (singleton) {
if (_instance) { if (_instance) {

View File

@ -24,6 +24,8 @@ public:
bool get_cached_body(const String &path, String *body); bool get_cached_body(const String &path, String *body);
void set_cached_body(const String &path, const String &body); void set_cached_body(const String &path, const String &body);
void clear();
FileCache(bool singleton = false); FileCache(bool singleton = false);
virtual ~FileCache(); virtual ~FileCache();
@ -43,7 +45,6 @@ protected:
}; };
std::mutex cache_mutex; std::mutex cache_mutex;
std::map<String, CacheEntry *> cache_map; std::map<String, CacheEntry *> cache_map;
private: private: