Package org.apache.wicket.markup
Class MarkupCache
- java.lang.Object
-
- org.apache.wicket.markup.MarkupCache
-
- All Implemented Interfaces:
IMarkupCache
public class MarkupCache extends Object implements IMarkupCache
This is Wicket's default IMarkupCache implementation. It will load the markup and cache it for fast retrieval.If the application is in development mode and a markup file changes, it'll automatically be removed from the cache and reloaded when needed.
MarkupCache is registered with
MarkupFactory
which in turn is registered withMarkupSettings
and thus can be replaced with a sub-classed version.- Author:
- Jonathan Locke, Juergen Donnerstag
- See Also:
MarkupSettings
,MarkupFactory
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
MarkupCache.DefaultCacheImplementation<K,V>
static interface
MarkupCache.ICache<K,V>
MarkupCache allows you to implement you own cache implementation.
-
Constructor Summary
Constructors Modifier Constructor Description protected
MarkupCache()
Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
Clear markup cache and force reload of all markup datastatic IMarkupCache
get()
A convenient helper to get the markup cache registered with the application.Markup
getMarkup(MarkupContainer container, Class<?> clazz, boolean enforceReload)
Gets any (immutable) markup resource for the container or any of its parent classes (markup inheritance)MarkupCache.ICache<String,Markup>
getMarkupCache()
Get a unmodifiable map which contains the cached data.IMarkupCacheKeyProvider
getMarkupCacheKeyProvider(MarkupContainer container)
Get the markup cache key provider to be usedprotected Markup
getMarkupFromCache(String cacheKey, MarkupContainer container)
Wicket's default implementation just uses the cacheKey to retrieve the markup from the cache.protected <K,V>
MarkupCache.ICache<K,V>newCacheImplementation()
Allows you to change the map implementation which will hold the cache data.protected Markup
onMarkupNotFound(String cacheKey, MarkupContainer container, Markup markup)
Will be called if the markup was not in the cache yet and could not be found either.protected Markup
putIntoCache(String locationString, MarkupContainer container, Markup markup)
Put the markup into the cache if cacheKey is not null and the cache does not yet contain the cacheKey.IMarkupFragment
removeMarkup(String cacheKey)
Note that this method will be called from a "cleanup" thread which might not have a thread local application.void
shutdown()
Will be called by the application while shutting down.int
size()
-
-
-
Constructor Detail
-
MarkupCache
protected MarkupCache()
Constructor.
-
-
Method Detail
-
get
public static IMarkupCache get()
A convenient helper to get the markup cache registered with the application.- Returns:
- The markup cache registered with the
Application
- See Also:
Application.getMarkupSettings()
,MarkupFactory.getMarkupCache()
-
clear
public void clear()
Description copied from interface:IMarkupCache
Clear markup cache and force reload of all markup data- Specified by:
clear
in interfaceIMarkupCache
-
shutdown
public void shutdown()
Description copied from interface:IMarkupCache
Will be called by the application while shutting down. It allows the markup cache to cleanup if necessary.- Specified by:
shutdown
in interfaceIMarkupCache
-
removeMarkup
public final IMarkupFragment removeMarkup(String cacheKey)
Note that this method will be called from a "cleanup" thread which might not have a thread local application.- Specified by:
removeMarkup
in interfaceIMarkupCache
- Returns:
- The markup removed from the cache. Null, if nothing was found.
- See Also:
MarkupResourceStream.getCacheKey()
-
size
public final int size()
- Specified by:
size
in interfaceIMarkupCache
- Returns:
- the number of elements currently in the cache.
-
getMarkupCache
public final MarkupCache.ICache<String,Markup> getMarkupCache()
Get a unmodifiable map which contains the cached data. The map key is of type String and the value is of type Markup.May be used to debug or iterate the cache content.
- Returns:
- cache implementation
-
getMarkup
public final Markup getMarkup(MarkupContainer container, Class<?> clazz, boolean enforceReload)
Description copied from interface:IMarkupCache
Gets any (immutable) markup resource for the container or any of its parent classes (markup inheritance)- Specified by:
getMarkup
in interfaceIMarkupCache
- Parameters:
container
- The original requesting markup containerclazz
- The class to get the associated markup for. If null, the container's class is used, but it can be a parent class of the container as well (markup inheritance)enforceReload
- The cache will be ignored and all, including inherited markup files, will be reloaded. Whatever is in the cache, it will be ignored- Returns:
- Markup resource
-
onMarkupNotFound
protected Markup onMarkupNotFound(String cacheKey, MarkupContainer container, Markup markup)
Will be called if the markup was not in the cache yet and could not be found either.Subclasses may change the default implementation. E.g. they might choose not to update the cache to enforce reloading of any markup not found. This might be useful in very dynamic environments. Additionally a non-caching IResourceStreamLocator should be used.
- Parameters:
cacheKey
-container
-markup
- Markup.NO_MARKUP- Returns:
- Same as parameter "markup"
- See Also:
ResourceSettings.setResourceStreamLocator(org.apache.wicket.core.util.resource.locator.IResourceStreamLocator)
-
putIntoCache
protected Markup putIntoCache(String locationString, MarkupContainer container, Markup markup)
Put the markup into the cache if cacheKey is not null and the cache does not yet contain the cacheKey. Return the markup stored in the cache if cacheKey is present already. More sophisticated implementations may call a container method to e.g. cache it per container instance.- Parameters:
locationString
- Ifnull
then ignore the cachecontainer
- The container this markup is for.markup
-- Returns:
- markup The markup provided, except if the cacheKey already existed in the cache, then the markup from the cache is provided.
-
getMarkupFromCache
protected Markup getMarkupFromCache(String cacheKey, MarkupContainer container)
Wicket's default implementation just uses the cacheKey to retrieve the markup from the cache. More sophisticated implementations may call a container method to e.g. ignore the cached markup under certain situations.- Parameters:
cacheKey
- If null, than the cache will be ignoredcontainer
-- Returns:
- null, if not found or to enforce reloading the markup
-
getMarkupCacheKeyProvider
public IMarkupCacheKeyProvider getMarkupCacheKeyProvider(MarkupContainer container)
Get the markup cache key provider to be used- Parameters:
container
- The MarkupContainer requesting the markup resource stream- Returns:
- IMarkupResourceStreamProvider
-
newCacheImplementation
protected <K,V> MarkupCache.ICache<K,V> newCacheImplementation()
Allows you to change the map implementation which will hold the cache data. By default it is a ConcurrentHashMap() in order to allow multiple thread to access the data in a secure way.- Type Parameters:
K
-V
-- Returns:
- new instance of cache implementation
-
-