2

As my question title says, is Memcache supposed to play well with Google cloud endpoints? Locally it does, I can store a key / value pair using JCache in my application and read it from within a Google Cloud Endpoints API method.

When I upload my application and run it on the cloud it returns null exactly as the way it happens when I've found out that we can't access sessions from inside of cloud endpoints...

And I doing something wrong or Google cloud endpoints isn't supposed to access the cache as well?

I really need to share some tokens safely between my application and cloud endpoints and I don't want to write / read from the Datastore (those are volatile tokens...). Any ideas?

Community
  • 1
  • 1
Anthony Accioly
  • 21,918
  • 9
  • 70
  • 118

1 Answers1

1

Endpoints definitely works with memcache, using the built-in API. I just tried the following trivial snippet within an API method and saw the incrementing values as expected:

String key = "key";
Integer cached = 0;

MemcacheService memcacheService = MemcacheServiceFactory.getMemcacheService();
memcacheService.setErrorHandler(new StrictErrorHandler());
cached = (Integer) memcacheService.get(key);
if (cached == null) {
  memcacheService.put(key, 0);
} else {
  memcacheService.put(key, cached + 1);
}

This should work for you, unless you have a specific requirement for JCache.

Dan Holevoet
  • 9,183
  • 1
  • 33
  • 49
  • Hi Dan, thanks for the input. I will try it and get in touch. (I've copied your code and indeed it works, now I just need to test if I can put values in the cache using a Servlet and read them in endpoints). Any particular reason for JCache not to work? – Anthony Accioly Nov 06 '13 at 17:10
  • It works fine with the low level API. Weird (but anyway, solved my problem, thanks). – Anthony Accioly Nov 08 '13 at 05:14
  • Integer is trivial enough. How would you make it work with a custom object such as `Dog` – Katedral Pillon Apr 19 '14 at 14:19