/** * Build a map of all the matching elements in all of the auxiliaries and memory. * <p> * @param pattern * @return a map of K key to ICacheElement<K, V> element, or an empty map if there is no * data in cache for any matching keys */ @Override public Map<K, ICacheElement<K, V>> getMatching( String pattern ) { return getMatching( pattern, false ); }
/** * Build a map of all the matching elements in all of the auxiliaries and memory. Do not try to * go remote or laterally for this data. * <p> * @param pattern * @return a map of K key to ICacheElement<K, V> element, or an empty map if there is no * data in cache for any matching keys */ public Map<K, ICacheElement<K, V>> localGetMatching( String pattern ) { return getMatching( pattern, true ); }
/** * Build a map of all the matching elements in all of the auxiliaries and memory. * <p> * @param pattern * @return a map of K key to ICacheElement<K, V> element, or an empty map if there is no * data in cache for any matching keys */ @Override public Map<K, ICacheElement<K, V>> getMatching( String pattern ) { return getMatching( pattern, false ); }
/** * Build a map of all the matching elements in all of the auxiliaries and memory. Do not try to * go remote or laterally for this data. * <p> * @param pattern * @return a map of K key to ICacheElement<K, V> element, or an empty map if there is no * data in cache for any matching keys */ public Map<K, ICacheElement<K, V>> localGetMatching( String pattern ) { return getMatching( pattern, true ); }
/** * Get multiple elements from the cache based on a set of cache keys. * <p> * This method returns the ICacheElement<K, V> wrapper which provides access to element info and other * attributes. * <p> * This returns a reference to the wrapper. Any modifications will be reflected in the cache. No * defensive copy is made. * <p> * This method is most useful if you want to determine things such as the how long the element * has been in the cache. * <p> * The last access time in the ElementAttributes should be current. * <p> * @param pattern key search pattern * @return a map of K key to ICacheElement<K, V> element, or empty map if no keys match the pattern */ @Override public Map<K, ICacheElement<K, V>> getMatchingCacheElements( String pattern ) { return this.getCacheControl().getMatching( pattern ); }
/** * Get multiple elements from the cache based on a set of cache keys. * <p> * This method returns the ICacheElement<K, V> wrapper which provides access to element info and other * attributes. * <p> * This returns a reference to the wrapper. Any modifications will be reflected in the cache. No * defensive copy is made. * <p> * This method is most useful if you want to determine things such as the how long the element * has been in the cache. * <p> * The last access time in the ElementAttributes should be current. * <p> * @param pattern key search pattern * @return a map of K key to ICacheElement<K, V> element, or empty map if no keys match the pattern */ @Override public Map<K, ICacheElement<K, V>> getMatchingCacheElements( String pattern ) { return this.getCacheControl().getMatching( pattern ); }
/** * Retrieve matching objects from the cache region this instance provides access to. * <p> * @param pattern - a key pattern for the objects stored * @return A map of key to values. These are stripped from the wrapper. */ @Override public Map<K, V> getMatching( String pattern ) { HashMap<K, V> unwrappedResults = new HashMap<K, V>(); Map<K, ICacheElement<K, V>> wrappedResults = this.getCacheControl().getMatching( pattern ); if ( wrappedResults != null ) { for (Map.Entry<K, ICacheElement<K, V>> entry : wrappedResults.entrySet()) { ICacheElement<K, V> element = entry.getValue(); if ( element != null ) { unwrappedResults.put( entry.getKey(), element.getVal() ); } } } return unwrappedResults; }
/** * Retrieve matching objects from the cache region this instance provides access to. * <p> * @param pattern - a key pattern for the objects stored * @return A map of key to values. These are stripped from the wrapper. */ @Override public Map<K, V> getMatching( String pattern ) { HashMap<K, V> unwrappedResults = new HashMap<K, V>(); Map<K, ICacheElement<K, V>> wrappedResults = this.getCacheControl().getMatching( pattern ); if ( wrappedResults != null ) { for (Map.Entry<K, ICacheElement<K, V>> entry : wrappedResults.entrySet()) { ICacheElement<K, V> element = entry.getValue(); if ( element != null ) { unwrappedResults.put( entry.getKey(), element.getVal() ); } } } return unwrappedResults; }
+ this.remoteCacheServerAttributes.isAllowClusterGet() + "]" ); elements = c.getMatching( pattern );
+ this.remoteCacheServerAttributes.isAllowClusterGet() + "]" ); elements = c.getMatching( pattern );
/** * Processes a get request. * <p> * If isAllowClusterGet is enabled we will treat this as a normal request of non-remote * origination. * <p> * @param cacheName * @param pattern * @param requesterId * @return Map * @throws IOException */ @Override public Map<K, ICacheElement<K, V>> processGetMatching( String cacheName, String pattern, long requesterId ) throws IOException { CompositeCache<K, V> cache = getCacheManager().getCache( cacheName ); boolean keepLocal = !remoteHttpCacheServerAttributes.isAllowClusterGet(); if ( keepLocal ) { return cache.localGetMatching( pattern ); } else { return cache.getMatching( pattern ); } }
/** * Processes a get request. * <p> * If isAllowClusterGet is enabled we will treat this as a normal request of non-remote * origination. * <p> * @param cacheName * @param pattern * @param requesterId * @return Map * @throws IOException */ @Override public Map<K, ICacheElement<K, V>> processGetMatching( String cacheName, String pattern, long requesterId ) throws IOException { CompositeCache<K, V> cache = getCacheManager().getCache( cacheName ); boolean keepLocal = !remoteHttpCacheServerAttributes.isAllowClusterGet(); if ( keepLocal ) { return cache.localGetMatching( pattern ); } else { return cache.getMatching( pattern ); } }
Map<?, ?> result1 = cache.getMatching( keyprefix1 + "\\S+" ); Map<?, ?> result2 = cache.getMatching( keyprefix2 + "\\S+" );
Map<?, ?> result1 = cache.getMatching( keyprefix1 + "\\S+" ); Map<?, ?> result2 = cache.getMatching( keyprefix2 + "\\S+" );
/** * Verify we try a disk aux on a getMatching call. * <p> * @throws IOException */ public void testGetMatching_NotOnDisk() throws IOException { // SETUP int maxMemorySize = 0; String cacheName = "testGetMatching_NotOnDisk"; String memoryCacheClassName = "org.apache.commons.jcs.engine.memory.lru.LRUMemoryCache"; ICompositeCacheAttributes cattr = new CompositeCacheAttributes(); cattr.setCacheName(cacheName); cattr.setMemoryCacheName( memoryCacheClassName ); cattr.setMaxObjects( maxMemorySize ); IElementAttributes attr = new ElementAttributes(); CompositeCache<String, Integer> cache = new CompositeCache<String, Integer>( cattr, attr ); MockAuxiliaryCache<String, Integer> diskMock = new MockAuxiliaryCache<String, Integer>(); diskMock.cacheType = CacheType.DISK_CACHE; @SuppressWarnings("unchecked") AuxiliaryCache<String, Integer>[] aux = new AuxiliaryCache[] { diskMock }; cache.setAuxCaches( aux ); // DO WORK cache.getMatching( "junk" ); // VERIFY assertEquals( "Wrong number of calls", 1, diskMock.getMatchingCallCount ); }
/** * Verify we try a disk aux on a getMatching call. * <p> * @throws IOException */ public void testGetMatching_NotOnDisk() throws IOException { // SETUP int maxMemorySize = 0; String cacheName = "testGetMatching_NotOnDisk"; String memoryCacheClassName = "org.apache.commons.jcs.engine.memory.lru.LRUMemoryCache"; ICompositeCacheAttributes cattr = new CompositeCacheAttributes(); cattr.setCacheName(cacheName); cattr.setMemoryCacheName( memoryCacheClassName ); cattr.setMaxObjects( maxMemorySize ); IElementAttributes attr = new ElementAttributes(); CompositeCache<String, Integer> cache = new CompositeCache<String, Integer>( cattr, attr ); MockAuxiliaryCache<String, Integer> diskMock = new MockAuxiliaryCache<String, Integer>(); diskMock.cacheType = CacheType.DISK_CACHE; @SuppressWarnings("unchecked") AuxiliaryCache<String, Integer>[] aux = new AuxiliaryCache[] { diskMock }; cache.setAuxCaches( aux ); // DO WORK cache.getMatching( "junk" ); // VERIFY assertEquals( "Wrong number of calls", 1, diskMock.getMatchingCallCount ); }
cache.getMatching( "junk" );
cache.getMatching( "junk" );