ability to get multiple elements with a single method call
"Chris Fairbanks" <[email protected]>
| Newsgroups | gmane.comp.jakarta.turbine.jcs.devel |
|---|---|
| Message-ID | <[email protected]> |
In order to help optimize for network latency when dealing with distributed
cache servers, I'd like to add the ability to fetch multiple cache elements
at once from a JCS cache. I've done the following by adding a
getCacheElements method which takes in a Set of keys and returns a map of
key->cached value.
The logic in each implementation goes as follows, for the most part: iterate
over the set of keys and call out to the already-existing get method, then
put the results into a map based on the key, then return it. I didn't do
any optimization like bundling the MySQL calls into a single get query with
multiple key values, although that would be an obvious followup. When
relevant (as in the CacheAccess class), getCacheElements simply calls out to
getMultiple on its ICache instance.
I'm attaching a diff patch with the changes I made in order to achieve
this. It's almost entirely additional methods, plus some javadocs cleanup
where I saw problems. We've been using this code in locally-compiled jar
form in our development environment for some time now without negative
impact, but we'd like to get it into the main JCS build if possible.
Thanks,
Chris Fairbanks
In ICacheAccess interface:
/**
* Get multiple elements from the cache based on a set of cache keys.
* <p>
* This method returns the ICacheElement 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 names set of Object cache keys
* @return a map of Object key to ICacheElement element, or empty map if
none of the keys are present
*/
Map getCacheElements( Set names );
In ICache interface:
/**
* Gets multiple items from the cache based on the given set of keys.
* <p>
* @param keys
* @return a map of Serializable key to ICacheElement element, or an
empty map if there is no data in cache for any of these keys
* @throws IOException
*/
Map getMultiple( Set keys )
throws IOException;
In ICacheService interface:
/**
* Gets multiple items from the cache based on the given set of keys.
* <p>
* @param cacheName
* @param keys
* @return a map of Serializable key to ICacheElement element, or an
empty map if there is no data in cache for any of these keys
* @throws ObjectNotFoundException
* @throws IOException
*/
Map getMultiple( String cacheName, Set keys )
throws ObjectNotFoundException, IOException;
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
get-multiple-patch.zip
(application/zip, 20.2 KB) - not displayed