namespace rlottie {
+/**
+ * @brief Configures rlottie model cache policy.
+ *
+ * Provides Library level control to configure model cache
+ * policy. Setting it to 0 will disable
+ * the cache as well as flush all the previously cached content.
+ *
+ * @param[in] cacheSize Maximum Model Cache size.
+ *
+ * @note to disable Caching configure with 0 size.
+ * @note to flush the current Cache content configure it with 0 and
+ * then reconfigure with the new size.
+ *
+ * @internal
+ */
+LOT_EXPORT void configureModelCacheSize(size_t cacheSize);
+
struct Color {
Color() = default;
Color(float r, float g , float b):_r(r), _g(g), _b(b){}
{
std::lock_guard<std::mutex> guard(mMutex);
+ if (!mcacheSize) return nullptr;
+
auto search = mHash.find(key);
return (search != mHash.end()) ? search->second : nullptr;
void add(const std::string &key, std::shared_ptr<LOTModel> value)
{
std::lock_guard<std::mutex> guard(mMutex);
+
+ if (!mcacheSize) return;
+
+ //@TODO just remove the 1st element
+ // not the best of LRU logic
+ if (mcacheSize == mHash.size()) mHash.erase(mHash.cbegin());
+
mHash[key] = std::move(value);
}
+ void configureCacheSize(size_t cacheSize)
+ {
+ std::lock_guard<std::mutex> guard(mMutex);
+ mcacheSize = cacheSize;
+
+ if (!mcacheSize) mHash.clear();
+ }
+
private:
LottieModelCache() = default;
std::unordered_map<std::string, std::shared_ptr<LOTModel>> mHash;
std::mutex mMutex;
+ size_t mcacheSize{10};
};
#else
}
std::shared_ptr<LOTModel> find(const std::string &) { return nullptr; }
void add(const std::string &, std::shared_ptr<LOTModel>) {}
+ void configureCacheSize(size_t) {}
};
#endif
+void LottieLoader::configureModelCacheSize(size_t cacheSize)
+{
+ LottieModelCache::instance().configureCacheSize(cacheSize);
+}
+
static std::string dirname(const std::string &path)
{
const char *ptr = strrchr(path.c_str(), '/');
class LottieLoader
{
public:
+ static void configureModelCacheSize(size_t cacheSize);
bool load(const std::string &filePath);
bool loadFromData(std::string &&jsonData, const std::string &key, const std::string &resourcePath);
std::shared_ptr<LOTModel> model();