i came up with a novel approach that works, but is sadly not
integrated with SqlAlchemy yet.  It was more "proof of concept" and
creates a parallel Object Model.

It's not "good" but it's simple and seems to work very well .

I'm just going to braindump what I do.  It might give you some
ideas....

* Under Pyramid, I attach a `cachingApi` instance to each request.

* The `cachingApi` searches for data in this order:
 * a per-request stash
 * a dogpile managed cache
 * a lazily accessed SqlAlchemy reader

* requests to `cachingApi` are called like this:
 * each request is for a `cacheRegion`, `object` , `query_method`, and
(query,attributes) :
 * request.cachingApi.get('objects','Useraccount','get_by_id',(1,))


* cachingApi has a few hooks :
  * _hooks__pre_cache - called on an object before it is stored.  at
the very least this turns a SqlAlchemy object of columns into a
dict.   It will often do additional string formatting , so we only
calculate once.
  * _hooks__post_cache - called on objects coming out of the cache.
this sets up lazy-loaded-attributes , which are mapped to other cache
objects or regions.  I also cast the dict into an "ObjectifiedDict"
class -- which just gives me attribute access.


In a perfect world I'd have this fully integrated with the SqlAlchemy
models ( or at least the caching operations that represent SqlAlchemy
models ).  It's worked really great though -- i can use the same Mako
templates whether I'm using the cache or sqlalchemy.

The performance gains were insane:
- No Caching : 1.5s request, 90+% of it database calls
- Caching - unprimed cache : 2.2s request, 90+% database calls
- Caching - primed cache : .01s request , 0 database calls
- Caching - average primed cache : .1s request , few database calls

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to