File tree Expand file tree Collapse file tree 1 file changed +8
-2
lines changed Expand file tree Collapse file tree 1 file changed +8
-2
lines changed Original file line number Diff line number Diff line change @@ -23,7 +23,7 @@ After that, you can just make queries to a model `YourModel`:
23
23
from flask_sqlalchemy_caching import FromCache
24
24
25
25
# cache is a Flask-Caching instance imported for your app init
26
- YourModel.query.options(FromCache(cache)).first ()
26
+ YourModel.query.options(FromCache(cache)).get ()
27
27
```
28
28
29
29
You also have ` RelationshipCache ` to enable lazy loading relationships from
@@ -34,12 +34,18 @@ from sqlalchemy.orm import lazyload
34
34
from flask_sqlalchemy_caching import RelationshipCache
35
35
36
36
rc = RelationshipCache(YourModel.some_relationship, cache)
37
- obj = YourModel.query.options(lazyload(YourModel.some_relationship), rc).first ()
37
+ obj = YourModel.query.options(lazyload(YourModel.some_relationship), rc).get ()
38
38
39
39
# make the query and cache the results for future queries
40
40
print (obj.some_relationship)
41
41
```
42
42
43
+ If there is a column in your table that is much more dynamic and you want to exclude it from
44
+ being cached, try using a deferred query like:
45
+ ``` python
46
+ YourModel.query.options(defer(' crazy_column' )).options(FromCache(cache)).get()
47
+ ```
48
+
43
49
Take a look at [ Dogpile Caching example] [ ] to more details about how
44
50
` CachingQuery ` works. Most changes to their were made just to integrate it
45
51
with Flask, Flask-SQLAlchemy and Flask-Caching instead of Dogpile.
You can’t perform that action at this time.
0 commit comments