Class MarkdownSlingCacheImpl
- java.lang.Object
-
- com.composum.ai.backend.slingbase.impl.MarkdownSlingCacheImpl
-
- All Implemented Interfaces:
ApproximateMarkdownServicePlugin,PageCachedValueService
public class MarkdownSlingCacheImpl extends Object implements ApproximateMarkdownServicePlugin, PageCachedValueService
Implements a cache for markdown of pages. We replicate the page resource tree below cacheRootPath (just with sling:Folder) and store the markdown in a property.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceMarkdownSlingCacheImpl.Config-
Nested classes/interfaces inherited from interface com.composum.ai.backend.slingbase.ApproximateMarkdownServicePlugin
ApproximateMarkdownServicePlugin.PluginResult
-
-
Field Summary
Fields Modifier and Type Field Description static StringPROPERTY_MARKDOWNThe property in the cache tree where the markdown is stored.protected org.apache.sling.api.resource.ResourceResolverFactoryresourceResolverFactorystatic StringSUFFIX_PAGE_MODIFICATION_DATESuffix for a property that saves the page modification date when the corresponding property was generated.
-
Constructor Summary
Constructors Constructor Description MarkdownSlingCacheImpl()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidactivate(MarkdownSlingCacheImpl.Config config)voidcacheMarkdown(@NotNull org.apache.sling.api.resource.Resource resource, @NotNull String markdown)An optional way to cache calculated markdowns - if a plugin implements this, it can retrieve that onApproximateMarkdownServicePlugin.maybeHandle(Resource, PrintWriter, ApproximateMarkdownService, SlingHttpServletRequest, SlingHttpServletResponse).voiddeactivate()protected static @Nullable CalendargetLastModified(@NotNull org.apache.sling.api.resource.Resource resource)protected org.apache.sling.api.resource.ResourcegetOrCreateCacheResource(org.apache.sling.api.resource.ResourceResolver serviceResolver, String path, boolean createIfNotPresent)StringgetPageCachedValue(String propertyName, org.apache.sling.api.resource.Resource resource)Reads a value that was cached with that property name from the cache.protected booleanisEnabled()protected static booleanisModified(@NotNull org.apache.sling.api.resource.Resource resource, org.apache.sling.api.resource.ValueMap cacheVM, String propertyName)ApproximateMarkdownServicePlugin.PluginResultmaybeHandle(org.apache.sling.api.resource.Resource resource, PrintWriter out, ApproximateMarkdownService service, org.apache.sling.api.SlingHttpServletRequest request, org.apache.sling.api.SlingHttpServletResponse response)Checks whether the resource should be handled by this plugin and if so, handles it by printing an appropriate markdown representation to the PrintWriter.voidputPageCachedValue(String propertyName, org.apache.sling.api.resource.Resource resource, String markdown)Writes a value that should be cached with that property name to the cache.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.composum.ai.backend.slingbase.ApproximateMarkdownServicePlugin
getImageUrl, getMasterLinks, resourceRendersAsComponentMatching
-
-
-
-
Field Detail
-
PROPERTY_MARKDOWN
public static final String PROPERTY_MARKDOWN
The property in the cache tree where the markdown is stored.- See Also:
- Constant Field Values
-
SUFFIX_PAGE_MODIFICATION_DATE
public static final String SUFFIX_PAGE_MODIFICATION_DATE
Suffix for a property that saves the page modification date when the corresponding property was generated. If the actual modification date is different, the cache is removed.- See Also:
- Constant Field Values
-
resourceResolverFactory
protected org.apache.sling.api.resource.ResourceResolverFactory resourceResolverFactory
-
-
Method Detail
-
activate
public void activate(MarkdownSlingCacheImpl.Config config)
-
deactivate
public void deactivate()
-
isEnabled
protected boolean isEnabled()
-
maybeHandle
@Nonnull public ApproximateMarkdownServicePlugin.PluginResult maybeHandle(@Nonnull org.apache.sling.api.resource.Resource resource, @Nonnull PrintWriter out, @Nonnull ApproximateMarkdownService service, @Nonnull org.apache.sling.api.SlingHttpServletRequest request, @Nonnull org.apache.sling.api.SlingHttpServletResponse response)
Description copied from interface:ApproximateMarkdownServicePluginChecks whether the resource should be handled by this plugin and if so, handles it by printing an appropriate markdown representation to the PrintWriter.- Specified by:
maybeHandlein interfaceApproximateMarkdownServicePlugin- Returns:
- what is already handled by this plugin. It is possible to write to the PrintWriter in any case.
-
getPageCachedValue
public String getPageCachedValue(String propertyName, @Nonnull org.apache.sling.api.resource.Resource resource)
Description copied from interface:PageCachedValueServiceReads a value that was cached with that property name from the cache.- Specified by:
getPageCachedValuein interfacePageCachedValueService
-
isModified
protected static boolean isModified(@NotNull @NotNull org.apache.sling.api.resource.Resource resource, org.apache.sling.api.resource.ValueMap cacheVM, String propertyName)
-
cacheMarkdown
public void cacheMarkdown(@NotNull @NotNull org.apache.sling.api.resource.Resource resource, @NotNull @NotNull String markdown)Description copied from interface:ApproximateMarkdownServicePluginAn optional way to cache calculated markdowns - if a plugin implements this, it can retrieve that onApproximateMarkdownServicePlugin.maybeHandle(Resource, PrintWriter, ApproximateMarkdownService, SlingHttpServletRequest, SlingHttpServletResponse).- Specified by:
cacheMarkdownin interfaceApproximateMarkdownServicePlugin
-
putPageCachedValue
public void putPageCachedValue(String propertyName, @Nonnull org.apache.sling.api.resource.Resource resource, @Nonnull String markdown)
Description copied from interface:PageCachedValueServiceWrites a value that should be cached with that property name to the cache.- Specified by:
putPageCachedValuein interfacePageCachedValueService
-
getLastModified
@Nullable protected static @Nullable Calendar getLastModified(@NotNull @NotNull org.apache.sling.api.resource.Resource resource)
-
getOrCreateCacheResource
protected org.apache.sling.api.resource.Resource getOrCreateCacheResource(@Nonnull org.apache.sling.api.resource.ResourceResolver serviceResolver, @Nonnull String path, boolean createIfNotPresent) throws org.apache.sling.api.resource.PersistenceException
- Throws:
org.apache.sling.api.resource.PersistenceException
-
-