Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

This page explains how to cache arbitrary objects in Magnolia. You can cache basically every object. This takes caching well beyond page and page fragment caching.

Table of Contents
maxLevel3

...

The functionality for caching arbitrary objects is provided by at least two modules.

...

This is an example of how to configure a cache using Ehcache 2. Here you will find documentation of all configuration options. 

...

This is an example of how to configure a cache using Ehcache 3. Here you will find documentation of all configuration options. 

...

Code Block
languagejava
void put(Object key, Object value);
 
void put(Object key, Object value, int timeToLiveInSeconds);

Arguments:

key

required

The identifier of the object to cache

value

required

The object to cache

timeToLiveInSeconds

optional

The lifetime of the cached object in seconds.

Tip: The lifetime also can be configured globally, and you can configure a flush policy to clear the cache when some condition is met, or you may want to delete cached objects programmatically (see #remove and #clear below).

Example:

Code Block
languagejava
public class MyClass {
    public Object put(Object key, Object value){
        Cache cache = cacheFactoryProvider.get().get().getCache("fooBarCache");
        cache.put(key, value);
        return value;
    }
    public Object put(Object key, Object value, int timeToLiveInSeconds){
        Cache cache = cacheFactoryProvider.get().get().getCache("fooBarCache");
        cache.put(key, value, timeToLiveInSeconds);
        return value;
    }
} 

...