First of all, I will explain the question. Persistence, I mean storing data outside the execution of a single request. This may not be the best title for the question, so feel free to edit it.
As I see it, there are three types of persistence in GAE, each of which is “closer” to the request itself:
Data store
Here, all the data is likely to be based. It may temporarily move to higher levels of storage, but in the end, this is where the data really is. Unfortunately, the storage request is repeatedly slow and consumes a lot of resources.
Use when ...
- storage of data that must be stored for an indefinite period of time.
Avoid use when ...
- receiving data that is often requested but rarely updated.
Memcache
This is a very complex caching mechanism that stores data in memory and ensures that all users read / write to the same cache. This is a much faster way to get / set data based on the key and price than when using the data warehouse. Unfortunately, data can only remain in memory for so long, and there is no guarantee that it will remain until you say so; data may disappear at any time if memory is required elsewhere.
Use when ...
- You need to receive data more often than you need to update. Even when data needs to be updated frequently, they can use their capabilities (if several skipped updates are considered acceptable) by setting up a task queue to save data from memcache to the data warehouse.
Avoid use when ...
- data should be updated frequently and should be updated upon receipt.
Global variables
This is not an official method of saving data, but it works. However, this is the least reliable method, and since it does not have data synchronization between servers, the stored data can be displayed differently for different users (but from what I found, the server rarely changes for the same user). Theoretically, this should however be the method that has the least overhead when getting / setting values and can use it.
Use when ...
- Is hell freezing? I don’t know ... I don’t have enough knowledge about what is going on behind the scenes to actually rely on this method. Discuss!
Avoid use when ...
- You rely on the fact that the data is the same on all servers.
Cookies
If the data is user-specific, it may be effective to save it as a cookie in a user browser. There are some pitfalls to watch out for:
- Security - the user can interfere with cookies, and attackers can do the same. To keep the content unreadable and unchanged for everyone, the cookie can be encrypted using the PyCrypto library available in GAE.
- Performance - since cookies are sent with every request (even images), it can add to the used bandwidth and slow down requests. One solution is to use a different domain for static content, so the browser will not send cookies for this content.
When should you use different types of persistence? How can they be combined to reduce / equalize the amount of resources spent?
Blixt source share