On Tue, Oct 27, 2009 at 6:17 PM, kousen <[email protected]> wrote:

>
> I'm using the Java API.  In my app, I store (only) the ISBN's of a
> series of books.  When I load the books, my service goes to Amazon and
> retrieves the rest of the information about the book from their web
> service.  Then I display all the books on a page.
>
> My service uses the JCache API, with a static attribute to represent
> the cache.  The (pseudo) code below is roughly analogous to what I
> actually do:
>
> public class AmazonBookService {
>  private static Cache cache;
>
>  static {
>     int secs = // expiration limit
>     cache = // get the factory, initialize the cache with expiration
> limit
>  }
>
>  public Book[] getBooks() {
>      // use a DAO to get the ISBNs from the datastore -- happens
> every request
>      // initialize results array
>      // for each ISBN:
>          // if book is in cache, add it to results
>          // if not, fetch data from Amazon, build book, and add it to
> cache and the results
>      // }
>      // return all the books
>  }
> }
>
> When I deploy the service, it seems to work, but most of the time when
> I refresh a web page it still take a long time.
>
> My questions are:
>
> 1. Is this the right way to use the cache?
>

Yes.  (And yes, the underlying cache is shared across all JVMs.  Static
variables are not.)


> 2. How can I check to see if it's working?
>

You can examine your cache hit rate and other details by calling
getCacheStatistics() on your JCache and converting the result to a string.


> 3. Is there a way I can send all the book requests to Amazon
> simultaneously?
>
>
Not yet.  Asynchronous API's are definitely planned, and URLFetch is mos
likely the first API that we will support.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to