Author |
Message |
04/25/2014 17:11:40
|
Crispy
neo
Joined: 04/22/2014 02:34:55
Messages: 4
Offline
|
(ehcache v2.8.2)
I created a simple test:
My test config:
Code:
<ehcache>
<cache name="testCache1"
maxEntriesLocalHeap="10"
statistics="true"
eternal="false">
<persistence strategy="none"/>
<searchable/>
</cache>
</ehcache>
My test class:
Code:
public class CacheTester
{
private static CacheManager cm;
private static Cache cache;
public static void main(String[] args)
{
cm = CacheManager.create();
cache = cm.getCache("testCache1");
CacheConfiguration cc = cache.getCacheConfiguration();
System.out.println("Stats on is: " +cc.getStatistics() );
if( !cache.isSearchable() ) { System.out.println("Cache " +cache.getName()+ " NOT searchable" ); }
cm.shutdown();
}
}
Result:
Code:
Stats on is: true
Cache testCache1 NOT searchable
(The stats bit is to check see if the correct ehcache.xml is being accessed).
Am I missing something?
Regards
Chris
|
|
|
04/28/2014 01:34:27
|
ljacomet
master
Joined: 03/06/2013 07:45:49
Messages: 79
Offline
|
Hi,
Just adding the <searchable/> tag in your configuration is not going to get you much.
Have a look at Ehcache Search Documentation and try with a more complete example.
|
Louis Jacomet
Terracotta engineer |
|
|
04/28/2014 01:43:40
|
Crispy
neo
Joined: 04/22/2014 02:34:55
Messages: 4
Offline
|
Yes, the documentation (I cut and paste) states:
----------
Making a Cache Searchable
Caches can be made searchable, on a per cache basis, either by configuration or programmatically.
By Configuration
Caches are made searchable by adding a <searchable/> tag to the ehcache.xml.
Code:
<cache name="cache2" maxBytesLocalHeap="16M" eternal="true" maxBytesLocalOffHeap="256M">
<persistence strategy="localRestartable"/>
<searchable/>
</cache>
This configuration will scan keys and values and, if they are of supported search types, add them as attributes called "key" and "value" respectively.
----------
Is the documentation not correct? I also tried some more 'advanced' examples, this did not work either. I have had to implement in code to get it working.
|
|
|
04/28/2014 05:47:47
|
ljacomet
master
Joined: 03/06/2013 07:45:49
Messages: 79
Offline
|
You are correct.
You are not missing anything as far as I can tell.
Could you have another ehcache.xml on your classpath?
What happens if you try accessing a cache with a different name, like "noSuchCache"?
|
Louis Jacomet
Terracotta engineer |
|
|
04/29/2014 02:53:24
|
Crispy
neo
Joined: 04/22/2014 02:34:55
Messages: 4
Offline
|
Louis
Have you tried the xml and code I submitted to see if you get the same result? Does it work for you?
Regards
Chris
|
|
|
04/29/2014 05:48:39
|
ljacomet
master
Joined: 03/06/2013 07:45:49
Messages: 79
Offline
|
Just did, the output is:
Stats on is: true
If I add an else clause with a print statement to the
if( !cache.isSearchable() )
condition, it is printed as expected.
Again, you should check if your classpath contains another ehcache.xml.
Also note that CacheManager.create() is a singleton CacheManager, so if it was created in the JVM before, you will get that one, not a new one.
You may want to try one of the CacheManager constructors, to make sure you end up loading the correct configuration.
|
Louis Jacomet
Terracotta engineer |
|
|
04/29/2014 08:23:16
|
Crispy
neo
Joined: 04/22/2014 02:34:55
Messages: 4
Offline
|
Many thanks. I'm working within Netbeans and there seems to be something weird with 'Save on compile' as I also get problems with persistence.xml writing a new ('useless') xml...
|
|
|
|