[Logo] Terracotta Discussion Forums (LEGACY READ-ONLY ARCHIVE)
  [Search] Search   [Recent Topics] Recent Topics   [Members]  Member Listing   [Groups] Back to home page 
[Register] Register / 
[Login] Login 
[Expert]
searchable tag not working?  XML
Forum Index -> Ehcache
Author Message
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
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
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.
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
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
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
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...
 
Forum Index -> Ehcache
Go to:   
Powered by JForum 2.1.7 © JForum Team