]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
update local_session_caching.py example for 1.4
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 5 Aug 2021 17:54:06 +0000 (13:54 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 5 Aug 2021 17:54:06 +0000 (13:54 -0400)
Fixes: #6858
Change-Id: I9b4113243f9ef32f27dcd1f7e9751923283eba2d

examples/dogpile_caching/local_session_caching.py

index 8f505ead7275f5036b11b19cd2ce9713df31c58a..e603cef642d9be2a2dd1ae45a3488e979dfde498 100644 (file)
@@ -13,6 +13,7 @@ with the basic operation of CachingQuery.
 from dogpile.cache.api import CacheBackend
 from dogpile.cache.api import NO_VALUE
 from dogpile.cache.region import register_backend
+from examples.dogpile_caching import environment
 
 
 class ScopedSessionBackend(CacheBackend):
@@ -76,7 +77,7 @@ if __name__ == "__main__":
     q = (
         Session.query(Person)
         .filter(Person.name == "person 10")
-        .execution_options(cache_options=FromCache("local_session"))
+        .options(FromCache("local_session"))
     )
 
     # load from DB
@@ -99,5 +100,8 @@ if __name__ == "__main__":
     # that would change the results of a cached query, such as
     # inserts, deletes, or modification to attributes that are
     # part of query criterion, still require careful invalidation.
-    cache, key = q._get_cache_plus_key()
-    assert person10 is cache.get(key)[0]
+    cache_key = FromCache("local_session")._generate_cache_key(
+        q._statement_20(), {}, environment.cache
+    )
+
+    assert person10 is regions["local_session"].get(cache_key)().scalar()