LRU Cache
功能:最近最少使用策略。
数据库查询缓存应用配置:
1 | <database-reference name="mydb"> |
2 | ... configure data source or driver manager settings... |
3 | <lru-cache size="1000"/> |
4 | </database-reference> |
方法查询缓存配置:
1 | <method-reference class-name="MyFromClauseWebServiceLib"> |
2 | <lru-cache size="1000"/> |
3 | </method-reference> |
Expire Time Cache
功能:通过配置设置查询结果的存活期,并定期清理过期的查询结果。
数据库查询缓存应用配置:
1 | <database-reference name="mydb"> |
2 | ... configure data source or driver manager settings... |
3 | <expiry-time-cache max-age-seconds="60" purge-interval-seconds="120" /> |
4 | </database-reference> |
方法查询缓存配置:
1 | <method-reference class-name="com.mycompany.MyFromClauseLookupLib"> |
2 | <expiry-time-cache max-age-seconds="10" purge-interval-seconds="10" ref-type="weak"/> |
3 | </method-reference> |
例子:
文件:event.xml
1 | <?xml version="1.0" encoding="UTF-8"?> |
2 | |
3 | <esper-configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
4 | xmlns="http://www.espertech.com/schema/esper" |
5 | xsi:noNamespaceSchemaLocation="esper-configuration-5-0.xsd"> |
6 | |
7 | <auto-import import-name = "cn.chenx.esper.xml.MyEvent" /> |
8 | |
9 | <method-reference class-name="MyEvent"> |
10 | <lru-cache size="1000"/> |
11 | </method-reference> |
12 | |
13 | </esper-configuration> |
文件名:orderMainTest.java
1 | // 添加配置(包所在路劲),方面后面的引用自动添加包名前缀 |
2 | Configuration config = new Configuration(); |
3 | config.addEventTypeAutoName("cn.chenx.esper.xml"); |
4 | URL url = orderMainTest.class.getResource("event.xml"); |
5 | config.configure(url); |
6 | |
7 | EPServiceProvider epServiceProvider = EPServiceProviderManager |
8 | .getDefaultProvider(config); |
9 | EPAdministrator epAdmin = epServiceProvider.getEPAdministrator(); |
10 | |
11 | String epsql = "select me.key as result from orderEvent as oe,method:MyEvent.getEvent(oe.salary) as me "; |
说明:
event.xml文件中的class-name="MyEvent",这里的MyEvent就是事件定义类。
外部事件应用(静态方法)
Joining Method Invocation Results
格式:
1 | method:class_name.method_name[(parameter_expressions)] |
说明:
method:固定关键字,class_name:类名,method_name:类中的静态方法,parameter_expressions:静态方法中的参数。
功能:
通过外部的静态方法构建事件源,需注意的是要结合其它事件使用。
应用场景:对数据库中的数据按条件查询等。
例子:
文件名:MyEvent.java
1 | public class MyEvent { |
2 | |
3 | public static orderBean getEvent(int salary){ |
4 | orderBean bean = new orderBean(); |
5 | |
6 | if ((salary % 2) == 0){ |
7 | bean.setKey("chenx1"); |
8 | bean.setValue(111); |
9 | }else { |
10 | bean.setKey("chenx2"); |
11 | bean.setValue(222); |
12 | } |
13 | return bean; |
14 | } |
15 | } |
文件名:orderMainTest
1 | // 添加配置(包所在路劲),方面后面的引用自动添加包名前缀 |
2 | Configuration config = new Configuration(); |
3 | config.addEventTypeAutoName("cn.chenx.esper.method"); |
4 | |
5 | // |
6 | EPServiceProvider epServiceProvider = EPServiceProviderManager |
7 | .getDefaultProvider(config); |
8 | EPAdministrator epAdmin = epServiceProvider.getEPAdministrator(); |
9 | |
10 | ConfigurationOperations configOper = epAdmin.getConfiguration(); |
11 | configOper.addImport(MyEvent.class); |
12 | |
13 | String epsql = "select me.key as result from orderEvent as oe,method:MyEvent.getEvent(oe.salary) as me "; |