com.alogic.cache.xscript.CacheClear Maven / Gradle / Ivy
package com.alogic.cache.xscript;
import com.alogic.cache.naming.CacheStoreFactory;
import com.anysoft.util.BaseException;
import org.apache.commons.lang3.StringUtils;
import com.alogic.cache.CacheObject;
import com.alogic.load.Store;
import com.alogic.xscript.ExecuteWatcher;
import com.alogic.xscript.Logiclet;
import com.alogic.xscript.LogicletContext;
import com.alogic.xscript.doc.XsObject;
import com.anysoft.util.Properties;
import com.anysoft.util.PropertiesConstants;
/**
* CacheClear
*
* @since 1.6.10.5
*
* @version 1.6.11.6 [20180103 duanyy]
* - 从alogic-cache中迁移过来
*/
public class CacheClear extends NS {
/**
* 缓存id
*/
protected String id = "id";
/**
* 父节点的上下文id
*/
protected String pid = "$cache";
protected String cacheId;
public CacheClear(String tag, Logiclet p) {
super(tag, p);
}
@Override
public void configure(Properties p){
super.configure(p);
id = PropertiesConstants.getRaw(p, "id", "");
pid = PropertiesConstants.getString(p,"pid", pid,true);
cacheId = PropertiesConstants.getString(p,"cacheId", "",true);
}
@Override
protected void onExecute(XsObject root,XsObject current, LogicletContext ctx,
ExecuteWatcher watcher) {
Store cache = StringUtils.isNotEmpty(cacheId)? CacheStoreFactory.get(cacheId):null;
if (cache == null) {
cache = ctx.getObject(pid);
if (cache == null) {
if (cache == null) {
throw new BaseException("core.e1001", "It must be in a cache context,check your together script.");
}
}
}
String idValue = ctx.transform(id);
if (StringUtils.isNotEmpty(idValue)){
cache.del(idValue);
}
}
}