1
14
15 package com.liferay.portal.cache.transactional;
16
17 import com.liferay.portal.kernel.cache.BasePortalCache;
18 import com.liferay.portal.kernel.cache.PortalCache;
19
20 import java.io.Serializable;
21
22 import java.util.ArrayList;
23 import java.util.Collection;
24 import java.util.List;
25
26
31 public class TransactionalPortalCache extends BasePortalCache {
32
33 public TransactionalPortalCache(PortalCache portalCache) {
34 _portalCache = portalCache;
35 }
36
37 public Collection<Object> get(Collection<String> keys) {
38 List<Object> values = new ArrayList<Object>(keys.size());
39
40 for (String key : keys) {
41 values.add(get(key));
42 }
43
44 return values;
45 }
46
47 public Object get(String key) {
48 Object result = null;
49
50 if (TransactionalPortalCacheHelper.isEnabled()) {
51 result = TransactionalPortalCacheHelper.get(_portalCache, key);
52
53 if (result == _nullHolder) {
54 return null;
55 }
56 }
57
58 if (result == null) {
59 result = _portalCache.get(key);
60 }
61
62 return result;
63 }
64
65 public void put(String key, Object obj) {
66 if (TransactionalPortalCacheHelper.isEnabled()) {
67 if (obj == null) {
68 obj = _nullHolder;
69 }
70
71 TransactionalPortalCacheHelper.put(_portalCache, key, obj);
72 }
73 else {
74 _portalCache.put(key, obj);
75 }
76 }
77
78 public void put(String key, Object obj, int timeToLive) {
79 if (TransactionalPortalCacheHelper.isEnabled()) {
80 if (obj == null) {
81 obj = _nullHolder;
82 }
83
84 TransactionalPortalCacheHelper.put(_portalCache, key, obj);
85 }
86 else {
87 _portalCache.put(key, obj, timeToLive);
88 }
89 }
90
91 public void put(String key, Serializable obj) {
92 if (TransactionalPortalCacheHelper.isEnabled()) {
93 if (obj == null) {
94 obj = _nullHolder;
95 }
96
97 TransactionalPortalCacheHelper.put(_portalCache, key, obj);
98 }
99 else {
100 _portalCache.put(key, obj);
101 }
102 }
103
104 public void put(String key, Serializable obj, int timeToLive) {
105 if (TransactionalPortalCacheHelper.isEnabled()) {
106 if (obj == null) {
107 obj = _nullHolder;
108 }
109
110 TransactionalPortalCacheHelper.put(_portalCache, key, obj);
111 }
112 else {
113 _portalCache.put(key, obj, timeToLive);
114 }
115 }
116
117 public void remove(String key) {
118 if (TransactionalPortalCacheHelper.isEnabled()) {
119 TransactionalPortalCacheHelper.remove(_portalCache, key);
120 }
121
122 _portalCache.remove(key);
123 }
124
125 public void removeAll() {
126 if (TransactionalPortalCacheHelper.isEnabled()) {
127 TransactionalPortalCacheHelper.removeAll(_portalCache);
128 }
129
130 _portalCache.removeAll();
131 }
132
133 private static Serializable _nullHolder = new String();
134
135 private PortalCache _portalCache;
136
137 }