1
14
15 package com.liferay.portal.servlet;
16
17 import com.liferay.portal.kernel.cache.MultiVMPool;
18 import com.liferay.portal.kernel.cache.PortalCache;
19 import com.liferay.portal.kernel.servlet.ImageServletToken;
20 import com.liferay.portal.kernel.util.StringPool;
21 import com.liferay.portal.servlet.filters.cache.CacheUtil;
22 import com.liferay.portlet.journalcontent.util.JournalContentUtil;
23
24
29 public class ImageServletTokenImpl implements ImageServletToken {
30
31 public static final String CACHE_NAME = ImageServletToken.class.getName();
32
33 public void afterPropertiesSet() {
34 _cache = _multiVMPool.getCache(CACHE_NAME);
35 }
36
37 public String getToken(long imageId) {
38 String key = _encodeKey(imageId);
39
40 String token = (String)_cache.get(key);
41
42 if (token == null) {
43 token = _createToken(imageId);
44
45 _cache.put(key, token);
46 }
47
48 return token;
49 }
50
51 public void resetToken(long imageId) {
52 String key = _encodeKey(imageId);
53
54 _cache.remove(key);
55
56
58 JournalContentUtil.clearCache();
59
60
62 CacheUtil.clearCache();
63 }
64
65 public void setMultiVMPool(MultiVMPool multiVMPool) {
66 _multiVMPool = multiVMPool;
67 }
68
69 private String _createToken(long imageId) {
70 return String.valueOf(System.currentTimeMillis());
71 }
72
73 private String _encodeKey(long imageId) {
74 return CACHE_NAME.concat(StringPool.POUND).concat(
75 String.valueOf(imageId));
76 }
77
78 private MultiVMPool _multiVMPool;
79 private PortalCache _cache;
80
81 }