Skip to content

Commit

Permalink
Merge pull request sakaiproject#352 from buckett/KNL-1271
Browse files Browse the repository at this point in the history
KNL-1271 Remove old caching code.
  • Loading branch information
buckett committed Apr 9, 2015
2 parents d9d264c + 0d531f1 commit 6cf1339
Show file tree
Hide file tree
Showing 38 changed files with 136 additions and 3,172 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ public void init()
{
// INIT the caches
long cacheRefreshRate = 43200; // 12 hours
SimpleConfiguration cacheConfig = new SimpleConfiguration(1000, 43200, 0); // 12 hours
SimpleConfiguration cacheConfig = new SimpleConfiguration(1000, cacheRefreshRate, 0); // 12 hours
cacheConfig.setStatisticsEnabled(true);
institutionalSubscriptionCache = new SubscriptionCache(
m_memoryService.createCache("org.sakaiproject.calendar.impl.BaseExternalCacheSubscriptionService.institutionalCache", cacheConfig));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -951,6 +951,12 @@
# DEFAULT: false
# memory.cache.statistics.force.disabled=true

# Register the EhCaches with JMX server
# If true then the EhCache will be registered with the JMX agent to make it easier to monitor the
# cache statistics.
# DEFAULT: true
# memory.ehcache.jmx=true

# Set event interval at which to report the current status of the site cache
# DEFAULT: 0
# org.sakaiproject.site.impl.SiteCacheImpl.cache.cacheEventReportInterval=0
Expand Down
41 changes: 9 additions & 32 deletions kernel/api/src/main/java/org/sakaiproject/memory/api/Cache.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
* Send questions to Aaron Zeckoski
* @author Aaron Zeckoski (azeckoski @ unicon.net) (azeckoski @ gmail.com)
*/
public interface Cache { // Cache<K, V> extends Iterable<Cache.Entry<K, V>>, Closeable {
public interface Cache <K, V> { // Cache<K, V> extends Iterable<Cache.Entry<K, V>>, Closeable {

/**
* Get the cached payload, or null if not there (or expired)<br/>
Expand All @@ -52,9 +52,9 @@ public interface Cache { // Cache<K, V> extends Iterable<Cache.Entry<K, V>>, Clo
*
* @param key the unique key for a cached object
* @return The cached payload, or null if the payload is not found in the cache,
* (use {@link #containsKey(String)} to differentiate between not found and stored null)
* (use {@link #containsKey(K)} to differentiate between not found and stored null)
*/
Object get(String key); // V get(K key);
V get(K key); // V get(K key);

/**
* Gets a collection of entries from the {@link Cache}, returning them as
Expand All @@ -77,7 +77,7 @@ public interface Cache { // Cache<K, V> extends Iterable<Cache.Entry<K, V>>, Clo
* types are incompatible with those that have been
* configured for the {@link Cache}
*/
Map<String, Object> getAll(Set<String> keys); // Map<K, V> getAll(Set<? extends K> keys);
Map<K, V> getAll(Set<? extends K> keys);

/**
* Test if an entry exists in the cache for a key,
Expand All @@ -92,7 +92,7 @@ public interface Cache { // Cache<K, V> extends Iterable<Cache.Entry<K, V>>, Clo
* @param key the unique key for a cached object
* @return true if the cache contains an entry with this key, false otherwise
*/
boolean containsKey(String key); // boolean containsKey(K key);
boolean containsKey(K key);

//JSR-107 void loadAll(Set<? extends K> keys, boolean replaceExistingValues, CompletionListener completionListener);

Expand All @@ -107,7 +107,7 @@ public interface Cache { // Cache<K, V> extends Iterable<Cache.Entry<K, V>>, Clo
* be distributable or able to be stored in the disk cache,
* null may be used (this will cause the cache to store a null value for this key)
*/
void put(String key, Object payload); // void put(K key, V value);
void put(K key, V payload);

//JSR-107 V getAndPut(K key, V value);

Expand Down Expand Up @@ -138,7 +138,7 @@ public interface Cache { // Cache<K, V> extends Iterable<Cache.Entry<K, V>>, Clo
* types are incompatible with those that have been
* configured for the {@link Cache}
*/
void putAll(java.util.Map<String, Object> map); //void putAll(java.util.Map<? extends K, ? extends V> map);
void putAll(Map<? extends K, ? extends V> map);

//JSR-107 boolean putIfAbsent(K key, V value);

Expand All @@ -157,7 +157,7 @@ public interface Cache { // Cache<K, V> extends Iterable<Cache.Entry<K, V>>, Clo
* @param key the unique key for a cached object
* @return true if the item was removed from the cache, false otherwise
*/
boolean remove(String key); // boolean remove(K key);
boolean remove(K key);

//JSR-107 boolean remove(K key, V oldValue);
//JSR-107 V getAndRemove(K key);
Expand Down Expand Up @@ -186,7 +186,7 @@ public interface Cache { // Cache<K, V> extends Iterable<Cache.Entry<K, V>>, Clo
* types are incompatible with those that have been
* configured for the {@link Cache}
*/
void removeAll(Set<String> keys); // void removeAll(Set<? extends K> keys);
void removeAll(Set<? extends K> keys);

/**
* Removes all of the mappings from this cache.
Expand Down Expand Up @@ -350,27 +350,4 @@ interface Entry<K, V> {
*/
boolean isDistributed();

// DEPRECATED METHODS - remove these before Sakai 11 release

/**
* Same as close
* Destroys the cache
* @deprecated since 2.9, will be removed in future versions, use close() instead
*/
void destroy();

/**
* Cache an object
*
* @param key
* The key with which to find the object.
* @param payload
* The object to cache.
* @param duration
* The time to cache the object (seconds).
* @deprecated Since Sakai 2.5.0
* @see Cache#put(String, Object)
*/
void put(Object key, Object payload, int duration);

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
* Send questions to Aaron Zeckoski
* @author Aaron Zeckoski (azeckoski @ unicon.net) (azeckoski @ gmail.com)
*/
public interface Configuration extends Serializable { // Configuration<K, V> extends Serializable
public interface Configuration<K, V> extends Serializable { // Configuration<K, V> extends Serializable

//Class<K> getKeyType();
//Class<V> getValueType();
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public interface MemoryService // CacheManager
* due to the current security settings
* JSR-107: <K, V, C extends Configuration<K, V>> Cache createCache(String cacheName, C configuration) throws IllegalArgumentException;
*/
<C extends Configuration> Cache createCache(String cacheName, C configuration);
<K, V, C extends Configuration<K, V>> Cache createCache(String cacheName, C configuration);

//<K, V> Cache<K, V> getCache(String cacheName, Class<K> keyType, Class<V> valueType);

Expand Down Expand Up @@ -125,7 +125,7 @@ public interface MemoryService // CacheManager
* @throws SecurityException when the operation could not be performed
* due to the current security settings
*/
Cache getCache(String cacheName); // <K, V> Cache<K, V> getCache(String cacheName);
<K, V>Cache<K, V> getCache(String cacheName);

/**
* Obtains an {@link Iterable} over the names of {@link Cache}s managed by the
Expand Down Expand Up @@ -271,16 +271,6 @@ public interface MemoryService // CacheManager
*/
Cache newCache(String cacheName, String pattern); // used in BaseAliasService, SiteCacheImpl, BaseUserDirectoryService (2), BaseCalendarService(3), ShareUserCacheImpl

/**
* Construct a multi-ref Cache. No automatic refresh: expire only, from time and events.
* NOT Cluster safe
*
* @param cacheName Load a defined bean from ComponentManager or create a default cache with this name.
* @deprecated since Sakai 2.9, this should no longer be used, it is not cluster safe or JSR-107 compatible
*/
@SuppressWarnings("deprecation") // TODO remove this
GenericMultiRefCache newGenericMultiRefCache(String cacheName); // used in BaseAliasService and SecurityService

/**
* Thrown to indicate an exception has occurred in the Cache.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
* Send questions to Aaron Zeckoski
* @author Aaron Zeckoski (azeckoski @ unicon.net) (azeckoski @ gmail.com)
*/
public class SimpleConfiguration implements Configuration {
public class SimpleConfiguration<K, V> implements Configuration<K, V> {

boolean stats = false;
long maxEntries = -1;
Expand Down
27 changes: 4 additions & 23 deletions kernel/api/src/main/java/org/sakaiproject/memory/mock/Cache.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* Partly functional (no listener/loader/stats support)
*/
@SuppressWarnings("deprecation") // TODO remove GenericMultiRefCache
public class Cache implements GenericMultiRefCache, org.sakaiproject.memory.api.Cache {
public class Cache implements org.sakaiproject.memory.api.Cache<String,Object> {

String name;
private Map<String, Object> map = new HashMap<String, Object>();
Expand Down Expand Up @@ -92,7 +92,7 @@ public Object get(String key) {
}

@Override
public Map<String, Object> getAll(Set<String> keys) {
public Map<String, Object> getAll(Set<? extends String> keys) {
Map<String, Object> m = new HashMap<String, Object>(this.map);
for (String key : keys) {
m.remove(key);
Expand All @@ -111,7 +111,7 @@ public void put(String key, Object object) {
}

@Override
public void putAll(Map<String, Object> map) {
public void putAll(Map<? extends String, ? extends Object> map) {
this.map.putAll(map);
}

Expand All @@ -122,7 +122,7 @@ public boolean remove(String key) {
}

@Override
public void removeAll(Set<String> keys) {
public void removeAll(Set<? extends String> keys) {
for (String key : keys) {
this.map.remove(key);
}
Expand All @@ -133,22 +133,8 @@ public void removeAll() {
clear();
}

// multi ref cache

@Override
public void put(String key, Object payload, String ref, Collection<String> dependRefs) {
map.put(key, payload);
}

// Sakai items below

/**
* @deprecated REMOVE THIS
*/
public void destroy() {
close();
}

@Override
public void attachLoader(CacheLoader cacheLoader) {
}
Expand All @@ -163,9 +149,4 @@ public String getDescription() {
return name;
}

@Override
public void put(Object key, Object payload, int duration) {
put((String)key, payload);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public Properties getProperties() {
}

@Override
public <C extends Configuration> Cache createCache(String cacheName, C configuration) {
public <K, V, C extends Configuration<K, V>> Cache createCache(String cacheName, C configuration) {
return newCache(cacheName, null, null);
}

Expand Down Expand Up @@ -110,12 +110,6 @@ public Cache newCache(String cacheName) {
return newCache(cacheName, null, null);
}

@SuppressWarnings("deprecation") // TODO remove GenericMultiRefCache
@Override
public GenericMultiRefCache newGenericMultiRefCache(String cacheName) {
return null;
}

@Override
public String getStatus() {
return caches.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,4 @@
<property name="serverConfigurationService" ref="org.sakaiproject.component.api.ServerConfigurationService" />
</bean>

<!--
a JMX Agent to make the Cache visable in JConsole
-->
<bean id="org.sakaiproject.memory.api.MemoryService.jmxAgent"
class="org.sakaiproject.memory.impl.MemoryServiceJMXAgent"
init-method="init" >
<property name="cacheManager"><ref bean="org.sakaiproject.memory.api.MemoryService.cacheManager"/></property>
<property name="registerCacheManager"><value>true</value></property>
<property name="registerCaches"><value>true</value></property>
<property name="registerCacheConfigurations"><value>true</value></property>
<property name="registerCacheStatistics"><value>true</value></property>
</bean>

</beans>
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ public abstract class BaseAliasService implements AliasService, SingleStorageUse
protected String m_relativeAccessPoint = null;

/** A cache of calls to the service and the results. */
protected Cache m_callCache = null; // TODO remove this after 10 - KNL-1229
/** The # seconds to cache gets. 0 disables the cache. */
protected int m_cacheSeconds = 0;

Expand Down Expand Up @@ -347,20 +346,6 @@ public void init()
m_storage = newStorage();
m_storage.open();

// <= 0 indicates no caching desired
if ((m_cacheSeconds > 0) && (m_cacheCleanerSeconds > 0))
{
boolean useLegacy = serverConfigurationService().getBoolean("memory.use.legacy", false); // TODO remove this after 10 merge
if (useLegacy) {
m_callCache = memoryService().newCache(
"org.sakaiproject.alias.api.AliasService.callCache",
aliasReference(""));
M_log.info("org.sakaiproject.alias.api.AliasService.callCache is enabled, will be removed after Sakai 10");
} else {
M_log.info("org.sakaiproject.alias.api.AliasService.callCache is disabled, will be removed after Sakai 10");
}
}

// register as an entity producer
entityManager().registerEntityProducer(this, REFERENCE_ROOT);

Expand Down Expand Up @@ -558,32 +543,10 @@ public String getTarget(String alias) throws IdUnusedException
{
// check the cache
String ref = aliasReference(alias);
if (m_callCache != null)
{
String t = (String) m_callCache.get(ref);
if ( t != null )
{
return t;
}
else
{
if (m_callCache.containsKey(ref))
{
M_log.warn("Null Cache Entry found, should not happen SAK-12447 ref="+ref);
}
}
}

BaseAliasEdit a = (BaseAliasEdit) m_storage.get(alias);
if (a == null) throw new IdUnusedException(alias);

// cache
if (m_callCache != null) {
if ( a.getTarget() != null ) {
m_callCache.put(ref, a.getTarget());
}
}

return a.getTarget();

} // getTarget
Expand Down
Loading

0 comments on commit 6cf1339

Please sign in to comment.