001
014
015 package com.liferay.portal.cache.keypool;
016
017 import com.liferay.portal.kernel.cache.CacheListener;
018 import com.liferay.portal.kernel.cache.CacheListenerScope;
019 import com.liferay.portal.kernel.cache.PortalCache;
020
021 import java.io.Serializable;
022
023 import java.util.ArrayList;
024 import java.util.Collection;
025 import java.util.List;
026
027
031 public class MultiVMKeyPoolPortalCache implements PortalCache {
032
033 public MultiVMKeyPoolPortalCache(
034 PortalCache clusterPortalCache, PortalCache localPortalCache) {
035
036 _clusterPortalCache = clusterPortalCache;
037 _localPortalCache = localPortalCache;
038 }
039
040 public void destroy() {
041 }
042
043 public Collection<Object> get(Collection<Serializable> keys) {
044 List<Object> values = new ArrayList<Object>(keys.size());
045
046 for (Serializable key : keys) {
047 values.add(get(key));
048 }
049
050 return values;
051 }
052
053 public Object get(Serializable key) {
054 if (key == null) {
055 return null;
056 }
057
058 return _localPortalCache.get(key);
059 }
060
061 public String getName() {
062 return _clusterPortalCache.getName();
063 }
064
065 public void put(Serializable key, Object obj) {
066 _clusterPortalCache.put(key, key);
067
068 _localPortalCache.put(key, obj);
069 }
070
071 public void put(Serializable key, Object obj, int timeToLive) {
072 _clusterPortalCache.put(key, key, timeToLive);
073
074 _localPortalCache.put(key, obj, timeToLive);
075 }
076
077 public void put(Serializable key, Serializable obj) {
078 _clusterPortalCache.put(key, key);
079
080 _localPortalCache.put(key, obj);
081 }
082
083 public void put(Serializable key, Serializable obj, int timeToLive) {
084 _clusterPortalCache.put(key, key, timeToLive);
085
086 _localPortalCache.put(key, obj, timeToLive);
087 }
088
089 public void registerCacheListener(CacheListener cacheListener) {
090 _clusterPortalCache.registerCacheListener(cacheListener);
091 }
092
093 public void registerCacheListener(
094 CacheListener cacheListener, CacheListenerScope cacheListenerScope) {
095
096 _clusterPortalCache.registerCacheListener(
097 cacheListener, cacheListenerScope);
098 }
099
100 public void remove(Serializable key) {
101 _clusterPortalCache.remove(key);
102 _localPortalCache.remove(key);
103 }
104
105 public void removeAll() {
106 _clusterPortalCache.removeAll();
107 _localPortalCache.removeAll();
108 }
109
110 public void unregisterCacheListener(CacheListener cacheListener) {
111 _clusterPortalCache.unregisterCacheListener(cacheListener);
112 }
113
114 public void unregisterCacheListeners() {
115 _clusterPortalCache.unregisterCacheListeners();
116 }
117
118 private PortalCache _clusterPortalCache;
119 private PortalCache _localPortalCache;
120
121 }