Index: kernel-impl/src/main/java/org/sakaiproject/site/impl/BaseSiteService.java =================================================================== --- kernel-impl/src/main/java/org/sakaiproject/site/impl/BaseSiteService.java (revision 308572) +++ kernel-impl/src/main/java/org/sakaiproject/site/impl/BaseSiteService.java (working copy) @@ -103,7 +103,7 @@ protected String m_relativeAccessPoint = null; /** A site cache. */ - protected SiteCacheImpl m_siteCache = null; + protected SiteCache m_siteCache = null; /** The name/bean for the User-Site cache. */ protected static final String USER_SITE_CACHE = "org.sakaiproject.site.api.SiteService.userSiteCache"; @@ -453,8 +453,12 @@ // <= 0 minutes indicates no caching desired if (m_cacheSeconds > 0) { - // build a synchronized map for the call cache, automatiaclly checking for expiration every 15 mins. - m_siteCache = new SiteCacheImpl(memoryService(), m_cacheCleanerSeconds, siteReference("")); + boolean useLegacy = serverConfigurationService().getBoolean("memory.use.legacy", false); // TODO remove this after 10 merge + if (useLegacy) { + m_siteCache = new SiteCacheImpl(memoryService(), m_cacheCleanerSeconds, siteReference("")); + } else { + m_siteCache = new SiteCacheSafe(memoryService(), eventTrackingService()); // ONLY keep this part -AZ + } } // Register our user-site cache property Index: kernel-impl/src/main/java/org/sakaiproject/site/impl/SiteCache.java =================================================================== --- kernel-impl/src/main/java/org/sakaiproject/site/impl/SiteCache.java (revision 0) +++ kernel-impl/src/main/java/org/sakaiproject/site/impl/SiteCache.java (working copy) @@ -0,0 +1,68 @@ +/****************************************************************************** + * $URL$ + * $Id$ + ****************************************************************************** + * + * Copyright (c) 2003-2014 The Apereo Foundation + * + * Licensed under the Educational Community License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://opensource.org/licenses/ecl2 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *****************************************************************************/ + +package org.sakaiproject.site.impl; + +import org.sakaiproject.site.api.Group; +import org.sakaiproject.site.api.SitePage; +import org.sakaiproject.site.api.ToolConfiguration; + +/** + * Makes it possible to swap out legacy and new site caches + * @author Aaron Zeckoski (azeckoski @ unicon.net) (azeckoski @ gmail.com) + */ +public interface SiteCache { + /** + * @param key the site reference + * @param payload a Site object OR Boolean (indicates site exists) + */ + void put(String key, Object payload); + + boolean containsKey(String key); + + /** + * @param key the site reference + * @return a Site object OR Boolean (indicates site exists) + */ + Object get(String key); + + void clear(); + + boolean remove(String key); + + /** + * @param toolId the tool id + * @return ToolConfiguration or null if not found in the cache + */ + ToolConfiguration getTool(String toolId); + + /** + * @param pageId the site page id + * @return SitePage or null if not in the cache + */ + SitePage getPage(String pageId); + + /** + * @param groupId the site group id + * @return Group or null if not in the cache + */ + Group getGroup(String groupId); +} Property changes on: kernel-impl/src/main/java/org/sakaiproject/site/impl/SiteCache.java ___________________________________________________________________ Added: svn:keywords ## -0,0 +1 ## +Id URL \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: kernel-impl/src/main/java/org/sakaiproject/site/impl/SiteCacheImpl.java =================================================================== --- kernel-impl/src/main/java/org/sakaiproject/site/impl/SiteCacheImpl.java (revision 308572) +++ kernel-impl/src/main/java/org/sakaiproject/site/impl/SiteCacheImpl.java (working copy) @@ -44,9 +44,9 @@ *
* SiteCacheImpl is a cache tuned for Site (and page / tool) access. *
+ * @deprecated after 10, remove this for Sakai 11 */ -public class SiteCacheImpl implements CacheEventListener -{ +public class SiteCacheImpl implements CacheEventListener, SiteCache { private static Log M_log = LogFactory.getLog(SiteCacheImpl.class); /** Map of a tool id to a cached site's tool configuration instance. */ @@ -102,7 +102,8 @@ * @param payload * The object to cache. */ - public void put(String key, Object payload) + @Override + public void put(String key, Object payload) { m_cache.put(key, payload); } @@ -114,7 +115,8 @@ * The cache key. * @return true if the key maps to a non-expired cache entry, false if not. */ - public boolean containsKey(String key) + @Override + public boolean containsKey(String key) { return m_cache.containsKey(key); } @@ -126,7 +128,8 @@ * The cache key. * @return The payload, or null if the payload is null, the key is not found, or the entry has expired (Note: use containsKey() to remove this ambiguity). */ - public Object get(String key) + @Override + public Object get(String key) { return m_cache.get(key); } @@ -134,7 +137,8 @@ /** * Clear all entries. */ - public void clear() + @Override + public void clear() { m_cache.clear(); } @@ -145,9 +149,10 @@ * @param key * The cache key. */ - public void remove(String key) + @Override + public boolean remove(String key) { - m_cache.remove(key); + return m_cache.remove(key); } /** @@ -157,7 +162,8 @@ * The tool's id. * @return The ToolConfiguration that has this id, from a cached site. */ - public ToolConfiguration getTool(String toolId) + @Override + public ToolConfiguration getTool(String toolId) { return (ToolConfiguration) m_tools.get(toolId); } @@ -169,7 +175,8 @@ * The page's id. * @return The SitePage that has this id, from a cached site. */ - public SitePage getPage(String pageId) + @Override + public SitePage getPage(String pageId) { return (SitePage) m_pages.get(pageId); } @@ -181,7 +188,8 @@ * The group id. * @return The Group that has this id, from a cached site. */ - public Group getGroup(String groupId) + @Override + public Group getGroup(String groupId) { return (Group) m_groups.get(groupId); } @@ -293,7 +301,7 @@ return; } - if (M_log.isDebugEnabled()) M_log.debug("SiteCache:" + if (M_log.isDebugEnabled()) M_log.debug("SiteCacheSafe:" + " eventCount: " + cacheEventCount + " tools: " + m_tools.size() + " pages: " + m_pages.size() Index: kernel-impl/src/main/java/org/sakaiproject/site/impl/SiteCacheSafe.java =================================================================== --- kernel-impl/src/main/java/org/sakaiproject/site/impl/SiteCacheSafe.java (revision 0) +++ kernel-impl/src/main/java/org/sakaiproject/site/impl/SiteCacheSafe.java (working copy) @@ -0,0 +1,335 @@ +/****************************************************************************** + * $URL: https://source.sakaiproject.org/svn/master/trunk/header.java $ + * $Id: header.java 307632 2014-03-31 15:29:37Z azeckoski@unicon.net $ + ****************************************************************************** + * + * Copyright (c) 2003-2014 The Apereo Foundation + * + * Licensed under the Educational Community License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://opensource.org/licenses/ecl2 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *****************************************************************************/ + +package org.sakaiproject.site.impl; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.sakaiproject.event.api.Event; +import org.sakaiproject.event.api.EventTrackingService; +import org.sakaiproject.memory.api.*; +import org.sakaiproject.site.api.Group; +import org.sakaiproject.site.api.Site; +import org.sakaiproject.site.api.SitePage; +import org.sakaiproject.site.api.ToolConfiguration; + +import java.util.Collection; +import java.util.Observable; +import java.util.Observer; +import java.util.Properties; + +/** + * A safe and modern version of the site cache which is compatible with distributed caches + * + * Uses multiple caches instead of maps and uses the new Sakai MemoryService and Cache APIs which are JSR-107 compliant + * + * @author Aaron Zeckoski (azeckoski @ unicon.net) (azeckoski @ gmail.com) + */ +public class SiteCacheSafe implements SiteCache, Cache, CacheEventListener