From 60e7dfe7e9f784818015a3a177a4d6c63ddec6b6 Mon Sep 17 00:00:00 2001 From: Relintai Date: Fri, 4 Feb 2022 22:03:22 +0100 Subject: [PATCH] Added clear method to FileCache. --- core/file_cache.cpp | 18 ++++++++++++++++++ core/file_cache.h | 3 ++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/core/file_cache.cpp b/core/file_cache.cpp index 91102eb..14c0b66 100644 --- a/core/file_cache.cpp +++ b/core/file_cache.cpp @@ -101,6 +101,24 @@ void FileCache::set_cached_body(const String &path, const String &body) { cache_mutex.unlock(); } +void FileCache::clear() { + cache_mutex.lock(); + + registered_files.clear(); + + for (std::map::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) { if (singleton) { if (_instance) { diff --git a/core/file_cache.h b/core/file_cache.h index 56b8738..f06ebc7 100644 --- a/core/file_cache.h +++ b/core/file_cache.h @@ -24,6 +24,8 @@ public: bool get_cached_body(const String &path, String *body); void set_cached_body(const String &path, const String &body); + void clear(); + FileCache(bool singleton = false); virtual ~FileCache(); @@ -43,7 +45,6 @@ protected: }; std::mutex cache_mutex; - std::map cache_map; private: