Skip to content

Commit 470f63f

Browse files
committed
📚 Updating README
With get instead of first, and with a defer example.
1 parent 922bb3d commit 470f63f

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ After that, you can just make queries to a model `YourModel`:
2323
from flask_sqlalchemy_caching import FromCache
2424

2525
# 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()
2727
```
2828

2929
You also have `RelationshipCache` to enable lazy loading relationships from
@@ -34,12 +34,18 @@ from sqlalchemy.orm import lazyload
3434
from flask_sqlalchemy_caching import RelationshipCache
3535

3636
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()
3838

3939
# make the query and cache the results for future queries
4040
print(obj.some_relationship)
4141
```
4242

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+
4349
Take a look at [Dogpile Caching example][] to more details about how
4450
`CachingQuery` works. Most changes to their were made just to integrate it
4551
with Flask, Flask-SQLAlchemy and Flask-Caching instead of Dogpile.

0 commit comments

Comments
 (0)