View Javadoc
1   /*
2    * Copyright (C) 2010 eXo Platform SAS.
3    *
4    * This is free software; you can redistribute it and/or modify it
5    * under the terms of the GNU Lesser General Public License as
6    * published by the Free Software Foundation; either version 2.1 of
7    * the License, or (at your option) any later version.
8    *
9    * This software is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12   * Lesser General Public License for more details.
13   *
14   * You should have received a copy of the GNU Lesser General Public
15   * License along with this software; if not, write to the Free
16   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
17   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
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   * @author <a href="mailto:julien.viet@exoplatform.com">Julien Viet</a>
38   * @version $Revision$
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;  // default to 10000 entries in FutureCache
49  
50    private static final int DEFAULT_CACHE_CLEANUP = 30;     // default 30s interval for cleanup thread
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  }