I have written a program to cache objects using Google Guava. My problem is how to pass additional parameters to Guava Load method. Here is the code. Below you see in this line - I have made fileId and pageno as key - cache.get(fileID+pageNo);. Now when cache.get is called and when that key is not in the cache - guava will call the load method of class PreviewCacheLoader which I have given below as well.
public class PreviewCache {
static final LoadingCache<String, CoreObject> cache = CacheBuilder.newBuilder()
.maximumSize(1000)
.expireAfterWrite(5, TimeUnit.MINUTES)
.build(new PreviewCacheLoader());
public CoreObject getPreview(String strTempPath, int pageNo, int requiredHeight, String fileID, String strFileExt, String ssoId) throws IOException
{
CoreObject coreObject = null;
try {
coreObject = cache.get(fileID+pageNo, HOW TO PASS pageNO and requiredHeight because I want to keep key as ONLY fileID+pageNo );
} catch (ExecutionException e) {
e.printStackTrace();
}
return coreObject;
}
}
How to pass parameters from above which are int and String to below Load method in addition to key parameter
public class PreviewCacheLoader extends CacheLoader<String, CoreObject> {
@Override
public CoreObject load(String fileIDpageNo, HOW TO GET pageNO and requiredHeight) throws Exception {
CoreObject coreObject = new CoreObject();
// MAKE USE OF PARAMETERS pageNO and requiredHeight
// Populate coreObject here
return coreObject;
}--
--
guava-...@googlegroups.com
Project site: http://guava-libraries.googlecode.com
This group: http://groups.google.com/group/guava-discuss
This list is for general discussion.
To report an issue: http://code.google.com/p/guava-libraries/issues/entry
To get help: http://stackoverflow.com/questions/ask (use the tag "guava")
---
You received this message because you are subscribed to the Google Groups "guava-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to guava-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/guava-discuss/0c282341-42d8-44cc-ae84-fe4b86177be6%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.