Search in sources :

Example 1 with Resource

use of org.apache.velocity.runtime.resource.Resource in project wcomponents by BorderTech.

the class VelocityCacheImpl method getCache.

/**
 * @return the cache instance
 */
protected synchronized Cache<Object, Resource> getCache() {
    Cache<Object, Resource> cache = Caching.getCache(CACHE_NAME, Object.class, Resource.class);
    if (cache == null) {
        final CacheManager mgr = Caching.getCachingProvider().getCacheManager();
        MutableConfiguration<Object, Resource> config = new MutableConfiguration<>();
        config.setTypes(Object.class, Resource.class);
        config.setExpiryPolicyFactory(AccessedExpiryPolicy.factoryOf(new Duration(TimeUnit.HOURS, 12)));
        // Velocity template classes are not serializable so use by ref.
        config.setStoreByValue(false);
        cache = mgr.createCache(CACHE_NAME, config);
    }
    return cache;
}
Also used : Resource(org.apache.velocity.runtime.resource.Resource) CacheManager(javax.cache.CacheManager) Duration(javax.cache.expiry.Duration) MutableConfiguration(javax.cache.configuration.MutableConfiguration)

Aggregations

CacheManager (javax.cache.CacheManager)1 MutableConfiguration (javax.cache.configuration.MutableConfiguration)1 Duration (javax.cache.expiry.Duration)1 Resource (org.apache.velocity.runtime.resource.Resource)1