For configuring Model Cache at runtime used configureModelCacheSize().
For configuring Model Cache at build time use cache flag to enable or disable.
* @brief Constructs an animation object from file path.
*
* @param[in] path Lottie resource file path
+ * @param[in] cachePolicy whether to cache or not the model data.
+ * use only when need to explicit disabl caching for a
+ * particular resource. To disable caching at library level
+ * use @see configureModelCacheSize() instead.
*
* @return Animation object that can render the contents of the
* Lottie resource represented by file path.
* @internal
*/
static std::unique_ptr<Animation>
- loadFromFile(const std::string &path);
+ loadFromFile(const std::string &path, bool cachePolicy=true);
/**
* @brief Constructs an animation object from JSON string data.
* @param[in] jsonData The JSON string data.
* @param[in] key the string that will be used to cache the JSON string data.
* @param[in] resourcePath the path will be used to search for external resource.
+ * @param[in] cachePolicy whether to cache or not the model data.
+ * use only when need to explicit disabl caching for a
+ * particular resource. To disable caching at library level
+ * use @see configureModelCacheSize() instead.
*
* @return Animation object that can render the contents of the
* Lottie resource represented by JSON string data.
* @internal
*/
static std::unique_ptr<Animation>
- loadFromData(std::string jsonData, const std::string &key, const std::string &resourcePath="");
+ loadFromData(std::string jsonData, const std::string &key,
+ const std::string &resourcePath="", bool cachePolicy=true);
/**
* @brief Returns default framerate of the Lottie resource.
*/
std::unique_ptr<Animation> Animation::loadFromData(
std::string jsonData, const std::string &key,
- const std::string &resourcePath)
+ const std::string &resourcePath, bool cachePolicy)
{
if (jsonData.empty()) {
vWarning << "jason data is empty";
LottieLoader loader;
if (loader.loadFromData(std::move(jsonData), key,
- (resourcePath.empty() ? " " : resourcePath))) {
+ (resourcePath.empty() ? " " : resourcePath), cachePolicy)) {
auto animation = std::unique_ptr<Animation>(new Animation);
animation->d->init(loader.model());
return animation;
return nullptr;
}
-std::unique_ptr<Animation> Animation::loadFromFile(const std::string &path)
+std::unique_ptr<Animation>
+Animation::loadFromFile(const std::string &path, bool cachePolicy)
{
if (path.empty()) {
vWarning << "File path is empty";
}
LottieLoader loader;
- if (loader.load(path)) {
+ if (loader.load(path, cachePolicy)) {
auto animation = std::unique_ptr<Animation>(new Animation);
animation->d->init(loader.model());
return animation;
return std::string(path, 0, len);
}
-bool LottieLoader::load(const std::string &path)
+bool LottieLoader::load(const std::string &path, bool cachePolicy)
{
- mModel = LottieModelCache::instance().find(path);
- if (mModel) return true;
+ if (cachePolicy) {
+ mModel = LottieModelCache::instance().find(path);
+ if (mModel) return true;
+ }
std::ifstream f;
f.open(path);
if (!mModel) return false;
- LottieModelCache::instance().add(path, mModel);
+ if (cachePolicy)
+ LottieModelCache::instance().add(path, mModel);
f.close();
}
}
bool LottieLoader::loadFromData(std::string &&jsonData, const std::string &key,
- const std::string &resourcePath)
+ const std::string &resourcePath, bool cachePolicy)
{
- mModel = LottieModelCache::instance().find(key);
- if (mModel) return true;
+ if (cachePolicy) {
+ mModel = LottieModelCache::instance().find(key);
+ if (mModel) return true;
+ }
LottieParser parser(const_cast<char *>(jsonData.c_str()),
resourcePath.c_str());
if (!mModel) return false;
- LottieModelCache::instance().add(key, mModel);
+ if (cachePolicy)
+ LottieModelCache::instance().add(key, mModel);
return true;
}
{
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);
+ bool load(const std::string &filePath, bool cachePolicy);
+ bool loadFromData(std::string &&jsonData, const std::string &key,
+ const std::string &resourcePath, bool cachePolicy);
std::shared_ptr<LOTModel> model();
-private:
+private:
std::shared_ptr<LOTModel> mModel;
};