Comments (13)
Looks like this was introduced when fixing #26
from ehcache-jcache.
@tarioch You configure the Cache
in ehcache.xml, but still create a JCacheConfiguration
for it? I must be confused, can you provide a small (even pseudo code, doesn't need to make javac happy) example of how to problem is experienced?
from ehcache-jcache.
Sure
I have an ehcache.xml and then do
Caching.getCachingProvider().getCacheManager().getCache("foo");
to retrieve the cache.
This triggers JCacheManager.refreshAllCaches() which does
allCaches.put(s, new JCache(this, new JCacheConfiguration(cache.getCacheConfiguration()), cache));
which then ends up in the failing code block.
from ehcache-jcache.
Oh ok... so the issue is what the JCacheConfiguration
"pretends", but effectively the Cache
does honor it, right? I misunderstood that. That being said it still needs fixing! I'll make sure that happens... Thanks!
from ehcache-jcache.
The issue I noticed is that, JCache.getValue() starts triggering a remove as it is actually reading this generated JCache config.
from ehcache-jcache.
@tarioch I'll try to put a test case together to reproduce this... I seem to see we'll expose the TTI & TTL values, but these may well be set in your config (along with the eternal flag), so that these get picked up, rather than them being 0?
from ehcache-jcache.
Line 843-846 in net.sf.ehcache.config.CacheConfiguration
(ehcache 2.8.3):
public final void setEternal(boolean eternal) {
checkDynamicChange();
isEternalValueConflictingWithTTIOrTTL(eternal, getTimeToLiveSeconds(), getTimeToIdleSeconds());
this.eternal = eternal;
if (eternal) {
setTimeToIdleSeconds(0);
setTimeToLiveSeconds(0);
}
}
If eternal
is true
, set timeToIdleSeconds
and timeToLiveSeconds
to 0
.
Line 93-108 in org.ehcache.jcache.JCacheConfiguration
(ehcache-jcache 1.0.1):
expiryPolicy = new ExpiryPolicy() {
@Override
public Duration getExpiryForCreation() {
return new Duration(TimeUnit.SECONDS, cacheConfiguration.getTimeToLiveSeconds());
}
@Override
public Duration getExpiryForAccess() {
return new Duration(TimeUnit.SECONDS, cacheConfiguration.getTimeToLiveSeconds());
}
@Override
public Duration getExpiryForUpdate() {
return getExpiryForCreation();
}
};
If eternal
is true
, the value of exipryForCreation
and expiryForAccess
will be 0
seconds duration.
Line 138-141 in org.ehcache.jcache.JCache
(ehcache-jcache 1.0.1):
private Element getElement(final K key) {
final Element element = ehcache.get(key);
if (element == null)
return null;
final Duration expiryForUpdate = cfg.getExpiryPolicy().getExpiryForAccess();
if(expiryForUpdate != null && expiryForUpdate.isZero()) {
ehcache.removeElement(element);
}
return element;
}
If the expireForAccess
is zero, the cached element will be removed when call JCache#get(K key)
. So, if you configure eternal="true"
in ehcache.xml
, the cache will be expired immediately when you call get(K key)
.
Add these codes in org.ehcache.jcache.JCacheConfiguration
may be fix it:
if(cacheConfiguration.isEternal()){
expiryPolicyFactory = EternalExpiryPolicy.factoryOf();
expiryPolicy = expiryPolicyFactory.create();
}else{
expiryPolicyFactory = null;
expiryPolicy = new ExpiryPolicy(){
//...
}
}
from ehcache-jcache.
Any reason this has not been fixed? The change is pretty simple, and presently its not possible to configure an eternal cache via ehcache.xml because of this. Unsure about the expiryPolicyFactory = null;
in example above, but this seems to resolve the problem for me:
if (cacheConfiguration.isEternal()) {
expiryPolicy = EternalExpiryPolicy.factoryOf().create();
}
else {
expiryPolicy = new ExpiryPolicy()
{
@Override
public Duration getExpiryForCreation() {
return new Duration(TimeUnit.SECONDS, cacheConfiguration.getTimeToLiveSeconds());
}
@Override
public Duration getExpiryForAccess() {
return new Duration(TimeUnit.SECONDS, cacheConfiguration.getTimeToLiveSeconds());
}
@Override
public Duration getExpiryForUpdate() {
return getExpiryForCreation();
}
};
}
expiryPolicyFactory = new FactoryBuilder.SingletonFactory<ExpiryPolicy>(expiryPolicy);
from ehcache-jcache.
Sorry for noise above, sometimes github linking is a bit of PITA
from ehcache-jcache.
Sorry, my bad. Remained assigned to me, but I was off on vacation. Back now though.
I'll get back to you. Did you sign the contributor agreement already?
See here: https://github.com/ehcache/ehcache3/wiki#contributor-agreement
from ehcache-jcache.
Ah the project is alive.. yay. Will sent over signed legal mumbo jumbo shortly.
from ehcache-jcache.
Cool! Thanks... Now, that being said, the project is slow moving though. I have to be honest with you: all our efforts are going into Ehcache3, this wrapper was a temporary solution for 2.x users. But all (including features that were only "proprietary" ones in the 2.x line, e.g. Offheap) go into the new dev line. Here: https://github.com/ehcache/ehcache3
from ehcache-jcache.
@alexsnaps understood, and we'll consume ehcache3 once it stabilizes, but until then we are moving to use javax.cache api to allow us to switch the backend, so having the adapter for ehcache2 is helping us move forward while ehcache3 becomes more realistic for usage.
from ehcache-jcache.
Related Issues (20)
- cache-annotations-cdi: java.lang.IllegalArgumentException: cacheValueParameter cannot be null HOT 1
- Update deps to latest versions
- Perform release of 1.0.0 to maven central HOT 1
- Expiration configured in ehcache.xml in not honoured HOT 8
- CacheLoaderException when reading from cache and no loader factory is specified HOT 6
- Default configuration in ehcache.xml is not used on created JCache instances HOT 3
- Use defaultCache to read default values for 107 unspecified props HOT 1
- JCacheStatMXBean.clear() clears the Cache?! HOT 1
- Could not create a cache named "default" through the JSR-107 API HOT 2
- Updating cache with EntryProcessor does not update HOT 2
- Support EHCache 2.4/2.6? HOT 4
- Race Condition in JCacheManager between createCache() and getCache() HOT 5
- PR #45 introduced a failure
- Error creating caches with a TTL HOT 5
- Read configuration from file path
- ExpiryPolicy on existing caches lost after calling getCache on non-existing cache HOT 3
- Source files without license headers
- Potential Unreleased Lock
- getCache(cacheName, keyType, valueType) doesn't work for pre-configured cache HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ehcache-jcache.