summaryrefslogtreecommitdiff
path: root/examples/beaker_caching/model.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2010-02-12 21:43:19 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2010-02-12 21:43:19 +0000
commita2a3b701c71b8c424c4e63ee455aed12db2c54e2 (patch)
treed0eaa112db9260fc9958bba05faece812d0a7c2f /examples/beaker_caching/model.py
parente0b40f88446b86a46e6c066b0cb85510c38c4d1b (diff)
downloadsqlalchemy-a2a3b701c71b8c424c4e63ee455aed12db2c54e2.tar.gz
- Changed the beaker cache example a bit to have a separate
RelationCache option for lazyload caching. This object does a lookup among any number of potential attributes more efficiently by grouping several into a common structure. Both FromCache and RelationCache are simpler individually.
Diffstat (limited to 'examples/beaker_caching/model.py')
-rw-r--r--examples/beaker_caching/model.py15
1 files changed, 8 insertions, 7 deletions
diff --git a/examples/beaker_caching/model.py b/examples/beaker_caching/model.py
index 4c043b42b..daae0d512 100644
--- a/examples/beaker_caching/model.py
+++ b/examples/beaker_caching/model.py
@@ -10,7 +10,7 @@ City --(has a)--> Country
"""
from sqlalchemy import Column, Integer, String, ForeignKey
from sqlalchemy.orm import relation
-from meta import Base, FromCache, Session
+from meta import Base, FromCache, Session, RelationCache
class Country(Base):
__tablename__ = 'country'
@@ -92,12 +92,13 @@ class Person(Base):
def format_full(self):
return "\t".join([str(x) for x in [self] + list(self.addresses)])
-# Caching options. A set of three FromCache options
+# Caching options. A set of three RelationCache options
# which can be applied to Query(), causing the "lazy load"
# of these attributes to be loaded from cache.
-cache_address_bits = (
- FromCache("default", "byid", PostalCode.city),
- FromCache("default", "byid", City.country),
- FromCache("default", "byid", Address.postal_code),
- )
+cache_address_bits = RelationCache("default", "byid", PostalCode.city).\
+ and_(
+ RelationCache("default", "byid", City.country)
+ ).and_(
+ RelationCache("default", "byid", Address.postal_code)
+ )