summaryrefslogtreecommitdiff
path: root/examples/dogpile_caching/helloworld.py
diff options
context:
space:
mode:
Diffstat (limited to 'examples/dogpile_caching/helloworld.py')
-rw-r--r--examples/dogpile_caching/helloworld.py43
1 files changed, 24 insertions, 19 deletions
diff --git a/examples/dogpile_caching/helloworld.py b/examples/dogpile_caching/helloworld.py
index 0dbde5eaf..eb565344e 100644
--- a/examples/dogpile_caching/helloworld.py
+++ b/examples/dogpile_caching/helloworld.py
@@ -21,28 +21,34 @@ people = Session.query(Person).options(FromCache("default")).all()
# 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()
+people_two_through_twelve = (
+ Session.query(Person)
+ .options(FromCache("default"))
+ .filter(Person.name.between("person 02", "person 12"))
+ .all()
+)
# 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")
-people_five_through_fifteen = Session.query(Person).\
- options(FromCache("default")).\
- filter(Person.name.between("person 05", "person 15")).\
- all()
+people_five_through_fifteen = (
+ Session.query(Person)
+ .options(FromCache("default"))
+ .filter(Person.name.between("person 05", "person 15"))
+ .all()
+)
# ... but using the same params as are already cached, no SQL
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")).\
- all()
+people_two_through_twelve = (
+ Session.query(Person)
+ .options(FromCache("default"))
+ .filter(Person.name.between("person 02", "person 12"))
+ .all()
+)
# invalidate the cache for the three queries we've done. Recreate
@@ -51,10 +57,9 @@ people_two_through_twelve = Session.query(Person).\
# same order, then call invalidate().
print("invalidating everything")
Session.query(Person).options(FromCache("default")).invalidate()
-Session.query(Person).\
- options(FromCache("default")).\
- filter(Person.name.between("person 02", "person 12")).invalidate()
-Session.query(Person).\
- options(FromCache("default", "people_on_range")).\
- filter(Person.name.between("person 05", "person 15")).invalidate()
-
+Session.query(Person).options(FromCache("default")).filter(
+ Person.name.between("person 02", "person 12")
+).invalidate()
+Session.query(Person).options(FromCache("default", "people_on_range")).filter(
+ Person.name.between("person 05", "person 15")
+).invalidate()