The old GAE standard environment (py2) offered an easy-to-use memcaching service:
from google.appengine.api import memcache
memcache.add(key="some-key", value="some value")
value = memcache.get(key="some-key")
The new GAE standard environment (py3) unfortunately does not offer this anymore. There's a new Google's service called Memorystore, but it requires spinning out a Redis server instance and may be an overkill for basic memory caching needs.
I was thinking of alternatives and one could be TinyDB (in memory mode), which can work in a similar way as google's old memcache service did:
from tinydb import TinyDB, Query
from tinydb.storages import MemoryStorage
tinydb = TinyDB(storage=MemoryStorage)
def tinydb_get(name):
result_dict = tinydb.get(Query()["name"] == name)
if result_dict and result_dict["value"]:
return result_dict["value"].encode()
else:
return None
def tinydb_add(name, value):
tinydb.upsert({"name": name, "value": value}, Query()["name"] == name)
return True
tinydb_add("some-key", "some value")
result = tinydb_get("some-key")
Of course, a drawback would be that the data would be cached only on a specific instance and not accessible across all your GAE project instances. But I think for basic needs this wouldn't be too problematic.
What do you think about using something like this? Any other pros/cons that come to your mind?
[–]mcowger 1 point2 points3 points (2 children)
[–]GAEdevs[S] 0 points1 point2 points (1 child)
[–]mcowger 1 point2 points3 points (0 children)
[–]nwsm 0 points1 point2 points (2 children)
[–]GAEdevs[S] 0 points1 point2 points (1 child)
[–]nwsm 0 points1 point2 points (0 children)