killbill-memoizeit

util: set TTL for audit caches By default, audit caches invalidation

3/30/2017 4:34:43 AM

Details

diff --git a/util/src/main/java/org/killbill/billing/util/dao/AuditSqlDao.java b/util/src/main/java/org/killbill/billing/util/dao/AuditSqlDao.java
index 30cee0c..7ca13e0 100644
--- a/util/src/main/java/org/killbill/billing/util/dao/AuditSqlDao.java
+++ b/util/src/main/java/org/killbill/billing/util/dao/AuditSqlDao.java
@@ -1,7 +1,9 @@
 /*
- * Copyright 2010-2011 Ning, Inc.
+ * Copyright 2010-2013 Ning, Inc.
+ * Copyright 2014-2017 Groupon, Inc
+ * Copyright 2014-2017 The Billing Project, LLC
  *
- * Ning licenses this file to you under the Apache License, version 2.0
+ * The Billing Project licenses this file to you under the Apache 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:
  *
@@ -36,7 +38,7 @@ import org.killbill.billing.util.entity.dao.EntitySqlDaoStringTemplate;
 
 /**
  * Note 1: cache invalidation has to happen for audit logs (which is tricky in the multi-nodes scenario).
- * For now, we're using a time-based eviction strategy (see timeToIdleSeconds and timeToLiveSeconds in ehcache.xml)
+ * For now, we're using a time-based eviction strategy (see ehcache.xml)
  * which is good enough: the cache will always get at least the initial CREATION audit log entry, which is the one
  * we really care about (both for Analytics and for Kaui's endpoints). Besides, we do cache invalidation properly
  * on our own node (see EntitySqlDaoWrapperInvocationHandler).
diff --git a/util/src/main/resources/ehcache.xml b/util/src/main/resources/ehcache.xml
index f6a2d7c..b2d732c 100644
--- a/util/src/main/resources/ehcache.xml
+++ b/util/src/main/resources/ehcache.xml
@@ -29,16 +29,29 @@
                                     http://www.ehcache.org/v3/clustered
                                     http://www.ehcache.org/schema/ehcache-clustered-ext-3.3.xsd">
     <ehcache:service>
-        <jsr107:defaults default-template="defaultCacheConfiguration" enable-management="true" enable-statistics="true"/>
+        <jsr107:defaults default-template="defaultCacheConfiguration" enable-management="true" enable-statistics="true">
+            <!-- See AuditSqlDao -->
+            <jsr107:cache name="audit-log" template="defaultShortTTLCacheConfiguration"/>
+            <jsr107:cache name="audit-log-via-history" template="defaultShortTTLCacheConfiguration"/>
+        </jsr107:defaults>
     </ehcache:service>
 
+    <ehcache:cache-template name="defaultShortTTLCacheConfiguration">
+        <ehcache:expiry>
+            <ehcache:ttl unit="seconds">20</ehcache:ttl>
+        </ehcache:expiry>
+
+        <ehcache:resources>
+            <ehcache:heap unit="entries">100000</ehcache:heap>
+        </ehcache:resources>
+    </ehcache:cache-template>
+
     <ehcache:cache-template name="defaultCacheConfiguration">
         <ehcache:expiry>
             <ehcache:none/>
         </ehcache:expiry>
 
         <ehcache:resources>
-            <!-- The maximal number of entries to be held in the Cache, prior to eviction starting -->
             <ehcache:heap unit="entries">100000</ehcache:heap>
         </ehcache:resources>
     </ehcache:cache-template>