]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- remove verbiage about "namespaces" from the dogpile example, [ticket:2862]
authorMike Bayer <mike_mp@zzzcomputing.com>
Sat, 7 Dec 2013 22:33:13 +0000 (17:33 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sat, 7 Dec 2013 22:36:26 +0000 (17:36 -0500)
- fix broken py2k/py3k isms

examples/dogpile_caching/advanced.py
examples/dogpile_caching/environment.py
examples/dogpile_caching/helloworld.py

index 6b0638ea4424469ed8f942e65ff14aafc987a52f..3e1e7a4389dde72eed05a045bb3cec233306d168 100644 (file)
@@ -1,15 +1,13 @@
 """advanced.py
 
 Illustrate usage of Query combined with the FromCache option,
-including front-end loading, cache invalidation, namespace techniques
-and collection caching.
+including front-end loading, cache invalidation and collection caching.
 
 """
 
-from environment import Session
-from model import Person, Address, cache_address_bits
-from caching_query import FromCache, RelationshipCache
-from sqlalchemy.orm import joinedload
+from .environment import Session
+from .model import Person, cache_address_bits
+from .caching_query import FromCache, RelationshipCache
 
 def load_name_range(start, end, invalidate=False):
     """Load Person objects on a range of names.
index f210d26acc5b0952a208f8fa655e6e62bfe4a68d..6370271d17d93538a2b9aa8d90af7556d9d51b1d 100644 (file)
@@ -10,7 +10,12 @@ from sqlalchemy.orm import scoped_session, sessionmaker
 from sqlalchemy.ext.declarative import declarative_base
 from dogpile.cache.region import make_region
 import os
-import md5
+from hashlib import md5
+import sys
+py2k = sys.version_info < (3, 0)
+
+if py2k:
+    input = raw_input
 
 # dogpile cache regions.  A home base for cache configurations.
 regions = {}
@@ -47,7 +52,7 @@ def md5_key_mangler(key):
     distill them into an md5 hash.
 
     """
-    return md5.md5(key).hexdigest()
+    return md5(key.encode('ascii')).hexdigest()
 
 # configure the "default" cache region.
 regions['default'] = make_region(
index e2e4d4f7861c291e87d37c6cec350dfcefd878d4..7513a33ef10773441b1ccfda59bef5d81527f55d 100644 (file)
@@ -8,31 +8,31 @@ from environment import Session
 from model import Person
 from caching_query import FromCache
 
-# load Person objects.  cache the result under the namespace "all_people".
-print "loading people...."
+# load Person objects.  cache the result in the "default" cache region
+print("loading people....")
 people = Session.query(Person).options(FromCache("default")).all()
 
 # remove the Session.  next query starts from scratch.
 Session.remove()
 
-# load again, using the same FromCache option. now they're cached
-# under "all_people", no SQL is emitted.
-print "loading people....again!"
+# load again, using the same FromCache option. now they're cached,
+# so no SQL is emitted.
+print("loading people....again!")
 people = Session.query(Person).options(FromCache("default")).all()
 
-# want to load on some different kind of query ?  change the namespace
-# you send to FromCache
-print "loading people two through twelve"
+# Specifying a different query produces a different cache key, so
+# these results are independently cached.
+print("loading people two through twelve")
 people_two_through_twelve = Session.query(Person).\
                             options(FromCache("default")).\
                             filter(Person.name.between("person 02", "person 12")).\
                             all()
 
-# the data is cached under the "namespace" you send to FromCache, *plus*
+# the data is cached under string structure of the SQL statement, *plus*
 # the bind parameters of the query.    So this query, having
 # different literal parameters under "Person.name.between()" than the
 # previous one, issues new SQL...
-print "loading people five through fifteen"
+print("loading people five through fifteen")
 people_five_through_fifteen = Session.query(Person).\
                             options(FromCache("default")).\
                             filter(Person.name.between("person 05", "person 15")).\
@@ -40,7 +40,7 @@ people_five_through_fifteen = Session.query(Person).\
 
 
 # ... but using the same params as are already cached, no SQL
-print "loading people two through twelve...again!"
+print("loading people two through twelve...again!")
 people_two_through_twelve = Session.query(Person).\
                             options(FromCache("default")).\
                             filter(Person.name.between("person 02", "person 12")).\
@@ -51,7 +51,7 @@ people_two_through_twelve = Session.query(Person).\
 # each Query, which includes at the very least the same FromCache,
 # same list of objects to be loaded, and the same parameters in the
 # same order, then call invalidate().
-print "invalidating everything"
+print("invalidating everything")
 Session.query(Person).options(FromCache("default")).invalidate()
 Session.query(Person).\
             options(FromCache("default")).\