skip to Main Content

I am trying to figure out how to access Google App Engine Memcache service from outside Google App Engine. Any help on how this can be done would be greatly appreciated.

Thanks in advance!

3

Answers


  1. No, AFAIK the Memcache service is not available outside GAE. To be even more specific it is only available inside the GAE standard environment, it is unavailable in the GAE flexible environment.

    But some of the alternate solutions suggested for GAE flexible users might be useable for you as well. From Memcache:

    The Memcache service is currently not available for the App Engine
    flexible environment. An alpha version of the memcache service will be
    available shortly. If you would like to be notified when the service
    is available, fill out this early access form.

    If you need access to a memcache service immediately, you can use the
    third party memcache service from Redis Labs. To access this service,
    see Caching Application Data Using Redis Labs Memcache.

    You can also use Redis Labs Redis Cloud, a third party fully-managed
    service. To access this service, see Caching Application Data Using
    Redis Labs Redis
    .

    Login or Signup to reply.
  2. I don’t think this is currently possible. I don’t know if there is any technical argument for this or if this decision has been made simply for billing purposes. But it seems like memcache is intended to be an integral part of App Engine. The only relevant discussion I could find is this feature request. It calls for possibility of accesing memcached data of one App Engine project by another App Engine project. It seems to me that Google didn’t consider such functionality to be beneficial. You could try filing your own feature request to make memcache a standalone service. In case you do not succeed (and I am afraid you won’t), here is a simple workaround.

    A simple workaround:

    Create a simple App Engine project which would serve as a facade over memcache service. This dummy App Engine project would simply translate your HTTP requests to memcache API calls and return the obtained data in the body of a HTTP response. For example, to retrieve a memcache record you could send a GET request such as:

    https://<your-poject-id>.appspot.com/get?key=<some-particular-key>
    

    This call would get “translated” into:

    memcache.get(<some-particular-key>);
    

    And the obtained data appended to the HTTP response.

    Since accessing memcache is free, you would only have to pay for instance time. I don’t know what through-put are you expecting, but I can imagine scenarios where you could even fit into the free daily quota (currently 28 hours/day). All in all, the intermediate App Engine project should not come with significant cost in neither performance nor price.

    Before using this workaround:

    The above snippet of code is intended for illustration purposes only. There still remain some issues to be dealt with before using this approach in production. For example, as pointed out by Suken, anyone would be able to access your memcache if they knew what requests to send. Here are four additional things I would personally do:

    1. Address the security issues by sending some authentication token with each request. An obvious necessity would be to make the calls over HTTPS to prevent man-in-the-middle attackers from obtaining this token. Note that App Engine’s appspot.com subdomains are accessible via HTTPS by default.

    2. Prefer batch API calls such as getAll() over their single record alternatives such as get(). Retrieving multiple records in one batch call is much faster than making multiple separate API calls.

    3. Use POST requests (instead of GET) to access the facade application. You won’t have to worry about your batch requests being to large. I only used GET request in the example above because it was easier to write.

    4. Check if such usage of App Engine doesn’t violate the Terms of Service. Personally, I don’t believe it does. And I don’t see why Google should mind. After all, you will be paying for instance hours.

    EDIT: After giving this some more thought, I believe that the suggested workaround is actually what Google presumes you to do. Given that the Goolge’s objective is to earn money, it would be unreasonable to provide a free service unless it was a part of a paid one. Of course, another billing schemes could be created. For example, allowing direct access only for developers who are willing to pay for dedicated memcache. The question is whether your use case is broad enough to convince Google to take some action.

    Login or Signup to reply.
  3. As stated by other users the Memcache is not offered as a service outside GAE (Google App Engine). I would like to point out that implementing GAE facade over Memcache service has security ramifications. Please note that facade GAE Memcache app will be exposed on the public internet like any other GAE service. I am assuming that you want to use Memcache for internal use only. Another aspect to think about is writing into memcache. If you intend to write to memcache from outside GAE, then definitely avoid facade implementation. If comprised anyone will be able to use you facade implementation as their own cache without paying for it 😉

    My suggestion is to spin up a stack using GCP Cloud Launcher. There are various stack templates available for both Redis and Memcache stacks. Further you can configure the template to use preemptible burstable instances to reduce the cost of your Memcache.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search