#647 - REFACTOR: L2 cache - remove cache warming support (from @CacheStrategy and API)

This commit is contained in:
Robin Bygrave committed 2016-04-12 23:44:24 +12:00
1 parent 061652a48e
commit 3fb9a7414c
17 files changed
+35 -181

No files matched your search

@@ -11,8 +11,6 @@ public class CacheOptions {
private String naturalKey;
private String warmingQuery;
private int maxIdleSecs;
private long maxSecsToLive;
@@ -51,20 +49,6 @@ public class CacheOptions {
this.readOnly = readOnly;
}
/**
* Return the query used to warm the cache.
*/
public String getWarmingQuery() {
return warmingQuery;
}
/**
* Set the cache warming query.
*/
public void setWarmingQuery(String warmingQuery) {
this.warmingQuery = warmingQuery;
}
/**
* Return true if a natural key is set.
*/
@@ -1,6 +1,5 @@
package com.avaje.ebeaninternal.server.core;
import com.avaje.ebean.EbeanServer;
import com.avaje.ebean.cache.ServerCacheFactory;
import com.avaje.ebean.cache.ServerCacheManager;
import com.avaje.ebean.cache.ServerCacheOptions;
@@ -32,8 +31,6 @@ import java.util.Iterator;
import java.util.List;
import java.util.Properties;
import java.util.ServiceLoader;
import java.util.Timer;
import java.util.TimerTask;
/**
* Default Server side implementation of ServerFactory.
@@ -138,13 +135,6 @@ public class DefaultContainer implements SpiContainer {
// register the server once it has been created
clusterManager.registerServer(server);
}
// warm the cache in 30 seconds
long sleepMillis = 1000 * serverConfig.getCacheWarmingDelay();
if (sleepMillis > 0) {
Timer timer = new Timer("EbeanCacheWarmer", true);
timer.schedule(new CacheWarmer(server, timer), sleepMillis);
}
}
// start any services after registering with clusterManager
@@ -364,21 +354,4 @@ public class DefaultContainer implements SpiContainer {
}
}
private static class CacheWarmer extends TimerTask {
private final EbeanServer server;
private final Timer timer;
CacheWarmer(EbeanServer server, Timer timer) {
this.server = server;
this.timer = timer;
}
public void run() {
server.runCacheWarming();
timer.cancel();
}
}
}
@@ -421,26 +421,6 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
return null;
}
/**
* Run the cache warming queries on all beans that have them defined.
*/
public void runCacheWarming() {
List<BeanDescriptor<?>> descList = beanDescriptorManager.getBeanDescriptorList();
for (int i = 0; i < descList.size(); i++) {
descList.get(i).runCacheWarming();
}
}
public void runCacheWarming(Class<?> beanType) {
BeanDescriptor<?> desc = beanDescriptorManager.getBeanDescriptor(beanType);
if (desc == null) {
String msg = "Is " + beanType + " an entity? Could not find a BeanDescriptor";
throw new PersistenceException(msg);
} else {
desc.runCacheWarming();
}
}
/**
* Compile a query. Only valid for ORM queries.
*/
@@ -895,13 +895,6 @@ public class BeanDescriptor<T> implements MetaBeanInfo, BeanType<T> {
return owner.getEncryptKey(tableName, columnName);
}
/**
* Execute the warming cache query (if defined) and load the cache.
*/
public void runCacheWarming() {
cacheHelp.runCacheWarming(ebeanServer);
}
/**
* Return true if this bean type has a default select clause that is not
* simply select all properties.
@@ -1,7 +1,5 @@
package com.avaje.ebeaninternal.server.deploy;
import com.avaje.ebean.EbeanServer;
import com.avaje.ebean.Query;
import com.avaje.ebean.bean.BeanCollection;
import com.avaje.ebean.bean.EntityBean;
import com.avaje.ebean.bean.EntityBeanIntercept;
@@ -88,26 +86,6 @@ final class BeanDescriptorCacheHelp<T> {
}
}
/**
* Execute the warming cache query (if defined) and load the cache.
*/
public void runCacheWarming(EbeanServer ebeanServer) {
if (cacheOptions == null) {
return;
}
String warmingQuery = cacheOptions.getWarmingQuery();
if (warmingQuery != null && warmingQuery.trim().length() > 0) {
Query<?> query = ebeanServer.createQuery(beanType, warmingQuery);
query.setUseCache(true);
query.setReadOnly(true);
query.setLoadBeanCache(true);
List<?> list = query.findList();
if (beanLog.isInfoEnabled()) {
beanLog.info("Loaded {} cache with [{}] beans", cacheName, list.size());
}
}
}
public void setUseCache(boolean useCache) {
if (useCache) {
getBeanCache();
@@ -218,7 +218,6 @@ public class AnnotationClass extends AnnotationParser {
if (cacheStrategy != null) {
cacheOptions.setUseCache(cacheStrategy.useBeanCache());
cacheOptions.setReadOnly(cacheStrategy.readOnly());
cacheOptions.setWarmingQuery(cacheStrategy.warmingQuery());
if (cacheStrategy.naturalKey().length() > 0) {
String propName = cacheStrategy.naturalKey().trim();
DeployBeanProperty beanProperty = descriptor.getBeanProperty(propName);