Class CachingInstanceTemplateManager
java.lang.Object
org.javarosa.core.model.instance.utils.CachingInstanceTemplateManager
- All Implemented Interfaces:
InstanceTemplateManager
public class CachingInstanceTemplateManager extends Object implements InstanceTemplateManager
Instance template manager that caches the template instances in memory. Useful for when deserializing
many saved forms of the same form type at once.
Instance templates are lazily loaded into the cache upon the first request for the instance of that type.
Instances stay cached until explicitly cleared.
Keeping too many FormInstances cached at once may exhaust your memory. It's best if all saved forms
being deserialized in bulk belong to a set of a few, known form types. It is possible to explicitly
set the allowed form types, such that any attempt to deserialize a form of a different type will throw
an error, instead of caching the new instance template.
- Author:
- Drew Roos
-
Constructor Summary
Constructors Constructor Description CachingInstanceTemplateManager()CachingInstanceTemplateManager(boolean restrictFormTypes) -
Method Summary
Modifier and Type Method Description voidaddFormType(int formID)Set a form type as allowed for caching.voidclearCache()Remove all model templates from the cache.FormInstancegetTemplateInstance(int formID)Return the template model for the given form type.voidresetFormTypes()Empty the list of allowed form types
-
Constructor Details
-
CachingInstanceTemplateManager
public CachingInstanceTemplateManager() -
CachingInstanceTemplateManager
public CachingInstanceTemplateManager(boolean restrictFormTypes)- Parameters:
restrictFormTypes- if true, only allowed form types will be cached; any requests for the templates for other form types will throw an error; the list of allowed types starts out empty; register allowed form types with addFormType(). if false, all form types will be handled and cached
-
-
Method Details
-
clearCache
public void clearCache()Remove all model templates from the cache. Frees up memory. -
addFormType
public void addFormType(int formID)Set a form type as allowed for caching. Only has an effect if this class has been set to restrict form types- Parameters:
formID-
-
resetFormTypes
public void resetFormTypes()Empty the list of allowed form types -
getTemplateInstance
Return the template model for the given form type. Serves the template out of the cache, if cached; fetches it fresh and caches it otherwise. If form types are restricted and the given form type is not allowed, throw an error- Specified by:
getTemplateInstancein interfaceInstanceTemplateManager- Returns:
-