Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for periodic cache clean up. #4009

Open
wants to merge 1 commit into
base: 4.10.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@

import static org.wso2.carbon.caching.impl.CachingConstants.CLEAR_ALL_PREFIX;
import static org.wso2.carbon.caching.impl.CachingConstants.ILLEGAL_STATE_EXCEPTION_MESSAGE;
import static org.wso2.carbon.caching.impl.Util.isPeriodicCacheCleanUpEnabled;

/**
* TODO: class description
* <p/>
Expand Down Expand Up @@ -1000,7 +1002,10 @@ public int compare(CacheEntry o1, CacheEntry o2) {
long lastModified = localCacheEntry.getLastModified();
long now = System.currentTimeMillis();

if (now - lastAccessed >= accessedExpiryDuration || now - lastModified >= modifiedExpiryDuration) {
boolean performCleanup = isPeriodicCacheCleanUpEnabled() ? (now - lastAccessed >= accessedExpiryDuration) :
(now - lastAccessed >= accessedExpiryDuration || now - lastModified >= modifiedExpiryDuration);

if (performCleanup) {
expire(key);
if (log.isDebugEnabled()) {
log.debug("Expired: Cache:" + cacheName + ", entry:" + key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public final class CachingConstants {
public static final String ILLEGAL_STATE_EXCEPTION_MESSAGE = "The cache status is not STARTED";
public static final String CACHE_INVALIDATION_IMPL = "Cache.CacheInvalidationImpl";
public static final String CACHE_INVALIDATION_PROPAGATION_ENABLED = "Cache.CachePropagationEnabled";
public static final String PERIODIC_CACHE_CLEANUP_ENABLED = "Cache.CachePeriodicCleanupEnabled";
public static final String DEFAULT_CACHE_INVALIDATION_CLASS = "org.wso2.carbon.caching.impl.clustering" +
".ClusterCacheInvalidationRequestSender";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,24 @@ public static boolean isCacheInvalidationPropagationEnabled() {
return false;
}

/**
* Return whether the cache periodic cleanup enabled or not.
*
* @return boolean.
*/
public static boolean isPeriodicCacheCleanUpEnabled() {

ServerConfigurationService serverConfigService = DataHolder.getInstance().getServerConfigurationService();
if (serverConfigService != null) {
String cacheCleanUp = serverConfigService.getFirstProperty(
CachingConstants.PERIODIC_CACHE_CLEANUP_ENABLED);
if (StringUtils.isNotEmpty(cacheCleanUp)) {
return Boolean.parseBoolean(cacheCleanUp.trim());
}
}
return false;
}

private Util() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,12 @@
{% else %}
<CacheInvalidationImpl>org.wso2.carbon.caching.impl.clustering.ClusterCacheInvalidationRequestSender</CacheInvalidationImpl>
{% endif %}
<{% if server.cache.propagation_enabled is defined %}
<CachePropagationEnabled>{{server.cache.propagation_enabled}}</CachePropagationEnabled>
{% endif %}
{% if server.cache.periodic_cleanup_enabled is defined %}
<CachePeriodicCleanupEnabled>{{server.cache.periodic_cleanup_enabled}}</CachePeriodicCleanupEnabled>
{% endif %}
</Cache>

<!--
Expand Down