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 interface
MarkdownSlingCacheImpl.Config
-
Nested classes/interfaces inherited from interface com.composum.ai.backend.slingbase.ApproximateMarkdownServicePlugin
ApproximateMarkdownServicePlugin.PluginResult
-
-
Field Summary
Fields Modifier and Type Field Description static String
PROPERTY_MARKDOWN
The property in the cache tree where the markdown is stored.protected org.apache.sling.api.resource.ResourceResolverFactory
resourceResolverFactory
static String
SUFFIX_PAGE_MODIFICATION_DATE
Suffix 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 void
activate(MarkdownSlingCacheImpl.Config config)
void
cacheMarkdown(@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)
.void
deactivate()
protected static @Nullable Calendar
getLastModified(@NotNull org.apache.sling.api.resource.Resource resource)
protected org.apache.sling.api.resource.Resource
getOrCreateCacheResource(org.apache.sling.api.resource.ResourceResolver serviceResolver, String path, boolean createIfNotPresent)
String
getPageCachedValue(String propertyName, org.apache.sling.api.resource.Resource resource)
Reads a value that was cached with that property name from the cache.protected boolean
isEnabled()
protected static boolean
isModified(@NotNull org.apache.sling.api.resource.Resource resource, org.apache.sling.api.resource.ValueMap cacheVM, String propertyName)
ApproximateMarkdownServicePlugin.PluginResult
maybeHandle(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.void
putPageCachedValue(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:ApproximateMarkdownServicePlugin
Checks 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:
maybeHandle
in 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:PageCachedValueService
Reads a value that was cached with that property name from the cache.- Specified by:
getPageCachedValue
in 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:ApproximateMarkdownServicePlugin
An optional way to cache calculated markdowns - if a plugin implements this, it can retrieve that onApproximateMarkdownServicePlugin.maybeHandle(Resource, PrintWriter, ApproximateMarkdownService, SlingHttpServletRequest, SlingHttpServletResponse)
.- Specified by:
cacheMarkdown
in interfaceApproximateMarkdownServicePlugin
-
putPageCachedValue
public void putPageCachedValue(String propertyName, @Nonnull org.apache.sling.api.resource.Resource resource, @Nonnull String markdown)
Description copied from interface:PageCachedValueService
Writes a value that should be cached with that property name to the cache.- Specified by:
putPageCachedValue
in 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
-
-