1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.exoplatform.services.portletcache;
21
22 import org.exoplatform.commons.cache.future.FutureCache;
23 import org.exoplatform.commons.cache.future.FutureExoCache;
24 import org.exoplatform.container.xml.InitParams;
25 import org.exoplatform.management.annotations.Managed;
26 import org.exoplatform.management.annotations.ManagedDescription;
27 import org.exoplatform.management.jmx.annotations.NameTemplate;
28 import org.exoplatform.management.jmx.annotations.Property;
29 import org.exoplatform.management.rest.annotations.RESTEndpoint;
30 import org.exoplatform.services.cache.CacheService;
31 import org.exoplatform.services.cache.ExoCache;
32 import org.exoplatform.services.log.ExoLogger;
33 import org.exoplatform.services.log.Log;
34 import org.picocontainer.Startable;
35
36
37
38
39
40
41 @Managed
42 @NameTemplate( { @Property(key = "view", value = "portal"),
43 @Property(key = "service", value = "fragmentcache"), @Property(key = "type", value = "content") })
44 @ManagedDescription("FragmentCache Service")
45 @RESTEndpoint(path = "fragmentcacheservice")
46 public class FragmentCacheService implements Startable {
47
48 private static final int DEFAULT_CACHE_SIZE = 10000;
49
50 private static final int DEFAULT_CACHE_CLEANUP = 30;
51
52
53 private static final Log LOG = ExoLogger.getLogger(FragmentCacheService.class.getName());
54
55 private final static String CACHE_NAME = "ecms.FragmentCacheService";
56
57
58 private ExoCache<WindowKey, MarkupFragment> markupCache_;
59 private FutureCache<WindowKey, MarkupFragment, PortletRenderContext> futureCache;
60
61 public FragmentCacheService(CacheService cacheService, InitParams params) {
62 markupCache_ = cacheService.getCacheInstance(CACHE_NAME);
63 futureCache = new FutureExoCache<WindowKey, MarkupFragment, PortletRenderContext>(new PortletRenderer(LOG), markupCache_);
64 }
65
66 public MarkupFragment getMarkupFragment(PortletRenderContext context, WindowKey key) {
67 return futureCache.get(context, key);
68 }
69
70 public void setCacheSize(int size) {
71 markupCache_.setMaxSize(size);
72 }
73
74 @Override
75 public void start() {
76 }
77
78 @Override
79 public void stop() {
80 }
81
82 }