caching - How granular should data in memcached be? -
I am curious about anything .. Will the generation of an RSS feed be "most efficient" to cache ? Or API response (like the response to / api / movies / info / a12345 ).
For example, should I cache the entire feed, and try and return back, as the Psuedo code:
id = GET_PARAMS ['id'] Cached = memcache.get ("feed_% s"% id) if not cached: None Cached: Returns cached: feed = gener_feed (id) Memcache.put ("feed_% s"% id, feed) Return feed < / Code> Or cache query results and generate documents each time?
Id = sanitize (GET_PARMS ['id']) query = query ("SELECT title, body posts from WHERE id = %%", id) cached_query_result = memcache.get (query.hash) ()) If cached_query_result: feed = gener_feed (Cached_query_result) returns feed and: query_result = query.execute () memcache.put ("feed_% s"% id, query_result) feed = generated_feed (query_result) (Or, some other way I remember?)
My experience For example, you should apply "SELECT title, body posts from WHERE id = %%" Uses Land. If it uses only the first one).
In the second version of the code, you memcache.get (query.hash ()) , but memcache.put ("feed_% s"%) Id, query_result ) . This will probably not work as you want (unless you have an unusual version of hash);)
I prefer to use something like query.hash () post-title-body-% id try to delete a video when it is stored in the cache , Because query.hash () . It can hang for months as a zombie-video.
By the way:
id = GET_PARMS ['id'] query = query ("select title, body terms by WHERE id = %%", id) Do you take anything and put it in the right SQL query? This is bad (the result of SQL injection attacks).
Comments
Post a Comment