org.apache.wicket.markup
Class MarkupCache

java.lang.Object
  extended by 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 IMarkupSettings and thus can be replaced with a subclassed version.

Author:
Jonathan Locke, Juergen Donnerstag
See Also:
IMarkupSettings

Nested Class Summary
 class MarkupCache.DefaultCacheImplementation<K,V>
           
static interface MarkupCache.ICache<K,V>
          MarkupCache allows you to implement you own cache implementation.
 
Constructor Summary
MarkupCache(Application application)
          Constructor.
 
Method Summary
 void clear()
          Clear markup cache and force reload of all markup data
 Markup getMarkup(MarkupContainer container, Class<?> clazz, boolean enforceReload)
          THIS IS NOT PART OF WICKET'S PUBLIC API.
protected  MarkupCache.ICache<CharSequence,Markup> getMarkupCache()
          Get a unmodifiable map which contains the cached data.
 IMarkupCacheKeyProvider getMarkupCacheKeyProvider(MarkupContainer container)
          Get the markup cache key provider to be used
protected  Markup getMarkupFromCache(CharSequence cacheKey, MarkupContainer container)
          Wicket's default implementation just uses the cacheKey to retrieve the markup from the cache.
protected  IMarkupLoader getMarkupLoader()
          In case there is a need to extend the default chain of MarkupLoaders
protected  IMarkupResourceStreamProvider getMarkupResourceStreamProvider(MarkupContainer container)
          Get the markup resource stream provider to be used
 MarkupStream getMarkupStream(MarkupContainer container, boolean enforceReload, boolean throwException)
          Gets a fresh markup stream that contains the (immutable) markup resource for this class.
 boolean hasAssociatedMarkup(MarkupContainer container)
          Check if container has associated markup
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)
          Will be called if the markup was not in the cache yet but could not be found either.
protected  Markup putIntoCache(String locationString, Markup markup)
          Deprecated. see putIntoCache(String, MarkupContainer, Markup)
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.
 Markup removeMarkup(String cacheKey)
          Remove the markup associated with the cache key from the cache including all dependent markups (markup inheritance)
 void shutdown()
          Will be called by the application while shutting down.
 int size()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MarkupCache

public MarkupCache(Application application)
Constructor.

Parameters:
application -
Method Detail

clear

public final void clear()
Description copied from interface: IMarkupCache
Clear markup cache and force reload of all markup data

Specified by:
clear in interface IMarkupCache
See Also:
IMarkupCache.clear()

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 interface IMarkupCache
See Also:
IMarkupCache.shutdown()

removeMarkup

public final Markup removeMarkup(String cacheKey)
Description copied from interface: IMarkupCache
Remove the markup associated with the cache key from the cache including all dependent markups (markup inheritance)

Specified by:
removeMarkup in interface IMarkupCache
Returns:
The markup removed from the cache. Null, if nothing was found.
See Also:
IMarkupCache.removeMarkup(java.lang.String)

getMarkupStream

public final MarkupStream getMarkupStream(MarkupContainer container,
                                          boolean enforceReload,
                                          boolean throwException)
Description copied from interface: IMarkupCache
Gets a fresh markup stream that contains the (immutable) markup resource for this class.

Specified by:
getMarkupStream in interface IMarkupCache
Parameters:
container - The container the markup should be associated with
enforceReload - The cache will be ignored and all, including inherited markup files, will be reloaded. Whatever is in the cache, it will be ignored
throwException - If true, throw an exception, if markup could not be found
Returns:
A stream of MarkupElement elements
See Also:
IMarkupCache.getMarkupStream(org.apache.wicket.MarkupContainer, boolean, boolean)

hasAssociatedMarkup

public final boolean hasAssociatedMarkup(MarkupContainer container)
Description copied from interface: IMarkupCache
Check if container has associated markup

Specified by:
hasAssociatedMarkup in interface IMarkupCache
Parameters:
container - The container the markup should be associated with
Returns:
True if this markup container has associated markup
See Also:
IMarkupCache.hasAssociatedMarkup(org.apache.wicket.MarkupContainer)

size

public final int size()
Specified by:
size in interface IMarkupCache
Returns:
the number of elements currently in the cache.
See Also:
IMarkupCache.size()

getMarkupCache

protected final MarkupCache.ICache<CharSequence,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.

Returns:
cache implementation

getMarkup

public final Markup getMarkup(MarkupContainer container,
                              Class<?> clazz,
                              boolean enforceReload)
THIS IS NOT PART OF WICKET'S PUBLIC API. DO NOT USE IT. I still don't like this method being part of the API but I didn't find a suitable other solution.

Specified by:
getMarkup in interface IMarkupCache
Parameters:
container - The original requesting markup container
clazz - 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
See Also:
IMarkupCache.getMarkup(org.apache.wicket.MarkupContainer, java.lang.Class, boolean)

onMarkupNotFound

protected Markup onMarkupNotFound(String cacheKey,
                                  MarkupContainer container)
Will be called if the markup was not in the cache yet but could not be found either.

Subclasses may change the default implementation. E.g. they might choose not update the cache to enforce reloading of any markup not found. This might be useful in very dynamic environments.

Parameters:
cacheKey -
container -
Returns:
Markup.NO_MARKUP

putIntoCache

@Deprecated
protected Markup putIntoCache(String locationString,
                                         Markup markup)
Deprecated. see putIntoCache(String, MarkupContainer, 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.

Parameters:
locationString - If null, than ignore the cache
markup -
Returns:
markup The markup provided, except if the cacheKey already existed in the cache, than the markup from the cache is provided.

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 - If null, than ignore the cache
container - The container this markup is for.
markup -
Returns:
markup The markup provided, except if the cacheKey already existed in the cache, than the markup from the cache is provided.

getMarkupFromCache

protected Markup getMarkupFromCache(CharSequence 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 ignored
container -
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

getMarkupResourceStreamProvider

protected IMarkupResourceStreamProvider getMarkupResourceStreamProvider(MarkupContainer container)
Get the markup resource stream provider to be used

Parameters:
container - The MarkupContainer requesting the markup resource stream
Returns:
IMarkupResourceStreamProvider

getMarkupLoader

protected IMarkupLoader getMarkupLoader()
In case there is a need to extend the default chain of MarkupLoaders

Returns:
MarkupLoader

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


Copyright © 2004-2011 Apache Software Foundation. All Rights Reserved.