Cheok Yan Cheng
Cheok Yan Cheng

Reputation: 42670

Google App Engine Shared Memcache is having short life span

I realize the shared memcache in Google App Engine, can only hold the key-value for a very short period. I have perform the following call for 20 times, at different timestamp.

_MEMCACHE_DURATION = 14*24*60*60
memcache.add(email, user_timestamp, _MEMCACHE_DURATION)

My expectation is, the key-value will last for 14 days. However, I find out the oldest item age is "1 hr 42 min"

When I look at documentation, I thought that valid time is up to 1 month : https://cloud.google.com/appengine/docs/python/memcache/functions#Client_add

I was wondering, is such behavior correct?

Upvotes: 1

Views: 173

Answers (3)

Zig Mandel
Zig Mandel

Reputation: 19835

read about the difference between shared and paid memcache in the official docs. shared comes with no guarantees about how long the data will remain there.

Official documentation: https://cloud.google.com/appengine/docs/developers-console/#memcache

Best practices for memcache: https://cloud.google.com/appengine/articles/best-practices-for-app-engine-memcache

Upvotes: 2

Dan Cornilescu
Dan Cornilescu

Reputation: 39814

You should typically not make assumptions about the lifespan of a memcache entry since the very next request may end up not finding the entry which can dissapear at any time for various reasons: https://cloud.google.com/appengine/docs/python/memcache/#Python_How_cached_data_expires (zero lifespan if you want).

I'd interpret the "(up to 1 month)" note as a maximum lifespan.

Upvotes: 2

Dave W. Smith
Dave W. Smith

Reputation: 24966

1 hour 42 minutes is a substantial improvement from when I last measured it (which was then a substantial improvement over the time before).

Unless you're paying for reserved memcache, it's a shared resource. It's best to think of it as a short-term cache, where short-term is measured in minutes. A good use of such caching is to improve performance across requests within a session.

Upvotes: 4

Related Questions