diff options
Diffstat (limited to 'examples/beaker_caching')
| -rw-r--r-- | examples/beaker_caching/__init__.py | 8 | ||||
| -rw-r--r-- | examples/beaker_caching/meta.py | 28 | ||||
| -rw-r--r-- | examples/beaker_caching/model.py | 20 | ||||
| -rw-r--r-- | examples/beaker_caching/relation_caching.py | 4 |
4 files changed, 30 insertions, 30 deletions
diff --git a/examples/beaker_caching/__init__.py b/examples/beaker_caching/__init__.py index 9c5fcc8fd..a4e8ec1f1 100644 --- a/examples/beaker_caching/__init__.py +++ b/examples/beaker_caching/__init__.py @@ -22,7 +22,7 @@ E.g.:: # specify that each Person's "addresses" collection comes from # cache too - q = q.options(RelationCache("default", "by_person", Person.addresses)) + q = q.options(RelationshipCache("default", "by_person", Person.addresses)) # query print q.all() @@ -39,7 +39,7 @@ The demo scripts themselves, in order of complexity, are run as follows:: python examples/beaker_caching/helloworld.py - python examples/beaker_caching/relation_caching.py + python examples/beaker_caching/relationship_caching.py python examples/beaker_caching/advanced.py @@ -63,8 +63,8 @@ Listing of files: helloworld.py - the basic idea. - relation_caching.py - Illustrates how to add cache options on - relation endpoints, so that lazyloads load from cache. + relationship_caching.py - Illustrates how to add cache options on + relationship endpoints, so that lazyloads load from cache. advanced.py - Further examples of how to use FromCache. Combines techniques from the first two scripts. diff --git a/examples/beaker_caching/meta.py b/examples/beaker_caching/meta.py index 57654b9c8..a4e43caf1 100644 --- a/examples/beaker_caching/meta.py +++ b/examples/beaker_caching/meta.py @@ -9,7 +9,7 @@ The three new concepts introduced here are: retrieves results in/from Beaker. * FromCache - a query option that establishes caching parameters on a Query - * RelationCache - a variant of FromCache which is specific + * RelationshipCache - a variant of FromCache which is specific to a query invoked during a lazy load. * _params_from_query - extracts value parameters from a Query. @@ -52,10 +52,10 @@ class CachingQuery(Query): session using Session.merge(load=False), which is a fast performing method to ensure state is present. - The FromCache and RelationCache mapper options below represent + The FromCache and RelationshipCache mapper options below represent the "public" method of configuring the "cache_region" and "cache_namespace" attributes. - RelationCache has the ability to be invoked upon lazy loaders embedded + RelationshipCache has the ability to be invoked upon lazy loaders embedded in an object graph. """ @@ -158,14 +158,14 @@ class FromCache(MapperOption): _set_cache_parameters(query, self.region, self.namespace, self.cache_key) -class RelationCache(MapperOption): +class RelationshipCache(MapperOption): """Specifies that a Query as called within a "lazy load" should load results from a cache.""" propagate_to_loaders = True def __init__(self, region, namespace, attribute): - """Construct a new RelationCache. + """Construct a new RelationshipCache. :param region: the cache region. Should be a region configured in the Beaker CacheManager. @@ -175,13 +175,13 @@ class RelationCache(MapperOption): lexical structure. :param attribute: A Class.attribute which - indicates a particular class relation() whose + indicates a particular class relationship() whose lazy loader should be pulled from the cache. """ self.region = region self.namespace = namespace - self._relation_options = { + self._relationship_options = { ( attribute.property.parent.class_, attribute.property.key ) : self } @@ -196,23 +196,23 @@ class RelationCache(MapperOption): mapper, key = query._current_path[-2:] for cls in mapper.class_.__mro__: - if (cls, key) in self._relation_options: - relation_option = self._relation_options[(cls, key)] + if (cls, key) in self._relationship_options: + relationship_option = self._relationship_options[(cls, key)] _set_cache_parameters( query, - relation_option.region, - relation_option.namespace, + relationship_option.region, + relationship_option.namespace, None) def and_(self, option): - """Chain another RelationCache option to this one. + """Chain another RelationshipCache option to this one. - While many RelationCache objects can be specified on a single + While many RelationshipCache objects can be specified on a single Query separately, chaining them together allows for a more efficient lookup during load. """ - self._relation_options.update(option._relation_options) + self._relationship_options.update(option._relationship_options) return self diff --git a/examples/beaker_caching/model.py b/examples/beaker_caching/model.py index daae0d512..6ea5e7904 100644 --- a/examples/beaker_caching/model.py +++ b/examples/beaker_caching/model.py @@ -9,8 +9,8 @@ City --(has a)--> Country """ from sqlalchemy import Column, Integer, String, ForeignKey -from sqlalchemy.orm import relation -from meta import Base, FromCache, Session, RelationCache +from sqlalchemy.orm import relationship +from meta import Base, FromCache, Session, RelationshipCache class Country(Base): __tablename__ = 'country' @@ -27,7 +27,7 @@ class City(Base): id = Column(Integer, primary_key=True) name = Column(String(100), nullable=False) country_id = Column(Integer, ForeignKey('country.id'), nullable=False) - country = relation(Country) + country = relationship(Country) def __init__(self, name, country): self.name = name @@ -39,7 +39,7 @@ class PostalCode(Base): id = Column(Integer, primary_key=True) code = Column(String(10), nullable=False) city_id = Column(Integer, ForeignKey('city.id'), nullable=False) - city = relation(City) + city = relationship(City) @property def country(self): @@ -56,7 +56,7 @@ class Address(Base): person_id = Column(Integer, ForeignKey('person.id'), nullable=False) street = Column(String(200), nullable=False) postal_code_id = Column(Integer, ForeignKey('postal_code.id')) - postal_code = relation(PostalCode) + postal_code = relationship(PostalCode) @property def city(self): @@ -77,7 +77,7 @@ class Person(Base): id = Column(Integer, primary_key=True) name = Column(String(100), nullable=False) - addresses = relation(Address, collection_class=set) + addresses = relationship(Address, collection_class=set) def __init__(self, name, *addresses): self.name = name @@ -92,13 +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 RelationCache options +# Caching options. A set of three RelationshipCache options # which can be applied to Query(), causing the "lazy load" # of these attributes to be loaded from cache. -cache_address_bits = RelationCache("default", "byid", PostalCode.city).\ +cache_address_bits = RelationshipCache("default", "byid", PostalCode.city).\ and_( - RelationCache("default", "byid", City.country) + RelationshipCache("default", "byid", City.country) ).and_( - RelationCache("default", "byid", Address.postal_code) + RelationshipCache("default", "byid", Address.postal_code) ) diff --git a/examples/beaker_caching/relation_caching.py b/examples/beaker_caching/relation_caching.py index 2aeb87bc0..f5f0fad69 100644 --- a/examples/beaker_caching/relation_caching.py +++ b/examples/beaker_caching/relation_caching.py @@ -1,4 +1,4 @@ -"""relation_caching.py +"""relationship_caching.py Load a set of Person and Address objects, specifying that related PostalCode, City, Country objects should be pulled from long @@ -15,7 +15,7 @@ for p in Session.query(Person).options(eagerload(Person.addresses), cache_addres print p.format_full() -print "\n\nIf this was the first run of relation_caching.py, SQL was likely emitted to "\ +print "\n\nIf this was the first run of relationship_caching.py, SQL was likely emitted to "\ "load postal codes, cities, countries.\n"\ "If run a second time, only a single SQL statement will run - all "\ "related data is pulled from cache.\n"\ |
