001
014
015 package com.liferay.portal.template;
016
017 import com.liferay.portal.kernel.cache.CacheListener;
018 import com.liferay.portal.kernel.cache.PortalCache;
019 import com.liferay.portal.kernel.cache.PortalCacheException;
020 import com.liferay.portal.kernel.cache.SingleVMPoolUtil;
021 import com.liferay.portal.kernel.template.TemplateResource;
022 import com.liferay.portal.kernel.util.StringPool;
023
024
027 public class TemplateResourceCacheListener
028 implements CacheListener<String, TemplateResource> {
029
030 public TemplateResourceCacheListener(String templateResourceLoaderName) {
031 String cacheName = TemplateResource.class.getName();
032
033 cacheName = cacheName.concat(StringPool.POUND).concat(
034 templateResourceLoaderName);
035
036 _portalCache = SingleVMPoolUtil.getCache(cacheName);
037 }
038
039 @Override
040 public void notifyEntryEvicted(
041 PortalCache<String, TemplateResource> portalCache, String key,
042 TemplateResource templateResource, int timeToLive)
043 throws PortalCacheException {
044
045 if (templateResource != null) {
046 _portalCache.remove(templateResource);
047 }
048 }
049
050 @Override
051 public void notifyEntryExpired(
052 PortalCache<String, TemplateResource> portalCache, String key,
053 TemplateResource templateResource, int timeToLive)
054 throws PortalCacheException {
055
056 if (templateResource != null) {
057 _portalCache.remove(templateResource);
058 }
059 }
060
061 @Override
062 public void notifyEntryPut(
063 PortalCache<String, TemplateResource> portalCache, String key,
064 TemplateResource templateResource, int timeToLive)
065 throws PortalCacheException {
066 }
067
068 @Override
069 public void notifyEntryRemoved(
070 PortalCache<String, TemplateResource> portalCache, String key,
071 TemplateResource templateResource, int timeToLive)
072 throws PortalCacheException {
073
074 if (templateResource != null) {
075 _portalCache.remove(templateResource);
076 }
077 }
078
079 @Override
080 public void notifyEntryUpdated(
081 PortalCache<String, TemplateResource> portalCache, String key,
082 TemplateResource templateResource, int timeToLive)
083 throws PortalCacheException {
084
085 if (templateResource != null) {
086 _portalCache.remove(templateResource);
087 }
088 }
089
090 @Override
091 public void notifyRemoveAll(
092 PortalCache<String, TemplateResource> portalCache)
093 throws PortalCacheException {
094
095 _portalCache.removeAll();
096 }
097
098 private final PortalCache<TemplateResource, ?> _portalCache;
099
100 }