Sling Models Caching Use Case && How to invalidate Sling Model Cache?



Hello Community, 

A. Can anyone please shed some knowledge of different ways that we can utilise the Sling Models caching feature?

B. Please explain the risks of using the Sling Models caching feature?
C. Please explain how we would invalidate Sling Model Cache?

Example Code:

@Model(adaptable = SlingHttpServletRequest.class, cache = true)
public class ModelClass {}


// assume that request is some SlingHttpServletRequest object
ModelClass object1 = request.adaptTo(ModelClass.class); // creates new instance of ModelClass
ModelClass object2 = modelFactory.createModel(request, ModelClass.class); // Sling Models returns the cached instance
assert object1 == object2;


Accepted Solutions (0)

Answers (1)

Answers (1)




What detail exactly isn't covered by the documentation you referenced? IIRC caching is enabled by default, and there should never be a need to manually invalidate that cache.