take a look at the example “dogpile caching”, essentially Query.__iter__() is 
where you make your results available:

http://docs.sqlalchemy.org/en/rel_0_9/orm/examples.html#module-examples.dogpile_caching
http://docs.sqlalchemy.org/en/rel_0_9/_modules/examples/dogpile_caching/caching_query.html



On Jan 13, 2014, at 6:30 PM, [email protected] wrote:

> Hi everyone!
> 
> I've subclassed Query so that filter_by() method checks a custom cache 
> backend before querying. The cache backend is a cache of objects, not 
> queries. So first I get a list of IDs from the database, then look up the 
> objects in my cache by ID. It works wonderfully except that what I end up 
> with a list of objects, and the filter_by() method must return self so that 
> the query can do method chaining. Where do I make the query's internal list 
> of results equal to the objects received from my cache? Here's where I'm at,
> 
> class CacheQuery(BaseQuery):
>     def filter_by(self, **kwargs):
>         ids = 
> self.session.query(self._primary_entity.type.id).filter_by(**kwargs)
>         flat_ids = [item[0] for item in ids.all()]
> 
>         results = [get_from_cache(self.session, self._primary_entity.type, 
> id) for id in flat_ids]
>         # what to do with results?
>         return self
> 
> -- 
> 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.
> For more options, visit https://groups.google.com/groups/opt_out.

Attachment: signature.asc
Description: Message signed with OpenPGP using GPGMail

Reply via email to