Note that there are some explanatory texts on larger screens.

plurals
  1. POWhere is the best place to put cache-evicting logic in an AppEngine application?
    text
    copied!<p>I've written an application for Google AppEngine, and I'd like to make use of the memcache API to cut down on per-request CPU time. I've profiled the application and found that a large chunk of the CPU time is in template rendering and API calls to the datastore, and after chatting with a co-worker I jumped (perhaps a bit early?) to the conclusion that caching a chunk of a page's rendered HTML would cut down on the CPU time per request significantly. The caching pattern is pretty clean, but the question of <em>where</em> to put this logic of caching and evicting is a bit of a mystery to me.</p> <p>For example, imagine an application's main page has an Announcements section. This section would need to be re-rendered after:</p> <ul> <li>first read for anyone in the account,</li> <li>a new announcement being added, and</li> <li>an old announcement being deleted</li> </ul> <p>Some options of where to put the <code>evict_announcements_section_from_cache()</code> method call:</p> <ul> <li>in the Announcement Model's <code>.delete()</code>, and <code>.put()</code> methods</li> <li>in the RequestHandler's <code>.post()</code> method</li> <li>anywhere else?</li> </ul> <p>Then in the RequestHandler's get page, I could potentially call <code>get_announcements_section()</code> which would follow the standard memcache pattern (check cache, add to cache on miss, return value) and pass that HTML down to the template for that chunk of the page.</p> <p>Is it the typical design pattern to put the cache-evicting logic in the Model, or the Controller/RequestHandler, or somewhere else? Ideally I'd like to avoid having evicting logic with tentacles all over the code.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload