On Jan 25, 2014, at 11:48 AM, Jonathan Rogers <jonathanrrog...@gmail.com> wrote:

> I am experimenting with the caching example and have it working as
> described. I have a number of mapped classes for tables which are static
> lookup tables. The rows in the tables will not change during the
> lifetime of application process. So, I would like to automatically apply
> a FromCache option to any query which simply returns an instance of a
> class mapped to one of the static lookup tables.
> 
> It seems that I should be able to apply a FromCache option to any Query
> which has only one entity which is one of the mapped classes I want to
> cache. However, I'm not sure what interface to Query would allow me to
> determine this. Has anyone solved a similar problem or have any
> suggestions for where to start?


when i used this I was able to apply a whole list of RelationshipCache options 
to all queries, that option as written is suited to this since it looks through 
query._current_path to identify first that it applies.

in the case of FromCache, the implementation in the example is more fixed, but 
I would likely look into further altering CachingQuery.__iter__ to also pull 
from a set of “fixed” cache options.   To see that a Query is against “A” for a 
given “session.query(A)” you can look in query._entities for exactly one entity 
which has “.mapper” set to the mapper you’re looking for.

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

Reply via email to