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 portalCacheName = TemplateResource.class.getName();
032
033 portalCacheName = portalCacheName.concat(StringPool.POUND).concat(
034 templateResourceLoaderName);
035
036 _portalCache = SingleVMPoolUtil.getCache(portalCacheName);
037 }
038
039 @Override
040 public void dispose() {
041 }
042
043 @Override
044 public void notifyEntryEvicted(
045 PortalCache<String, TemplateResource> portalCache, String key,
046 TemplateResource templateResource, int timeToLive)
047 throws PortalCacheException {
048
049 if (templateResource != null) {
050 _portalCache.remove(templateResource);
051 }
052 }
053
054 @Override
055 public void notifyEntryExpired(
056 PortalCache<String, TemplateResource> portalCache, String key,
057 TemplateResource templateResource, int timeToLive)
058 throws PortalCacheException {
059
060 if (templateResource != null) {
061 _portalCache.remove(templateResource);
062 }
063 }
064
065 @Override
066 public void notifyEntryPut(
067 PortalCache<String, TemplateResource> portalCache, String key,
068 TemplateResource templateResource, int timeToLive)
069 throws PortalCacheException {
070 }
071
072 @Override
073 public void notifyEntryRemoved(
074 PortalCache<String, TemplateResource> portalCache, String key,
075 TemplateResource templateResource, int timeToLive)
076 throws PortalCacheException {
077
078 if (templateResource != null) {
079 _portalCache.remove(templateResource);
080 }
081 }
082
083 @Override
084 public void notifyEntryUpdated(
085 PortalCache<String, TemplateResource> portalCache, String key,
086 TemplateResource templateResource, int timeToLive)
087 throws PortalCacheException {
088
089 if (templateResource != null) {
090 _portalCache.remove(templateResource);
091 }
092 }
093
094 @Override
095 public void notifyRemoveAll(
096 PortalCache<String, TemplateResource> portalCache)
097 throws PortalCacheException {
098
099 _portalCache.removeAll();
100 }
101
102 private final PortalCache<TemplateResource, ?> _portalCache;
103
104 }