Skip to content

Commit 87594aa

Browse files
committed
Updated README.
1 parent 1d60f82 commit 87594aa

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

README.rst

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ to the database.
66
Installation
77
------------
88

9+
.. image:: https://travis-ci.org/ui/django-cached_authentication_middleware.png?branch=master
10+
11+
912
* Install via pypi::
1013

1114
pip install django-cached_authentication_middleware
@@ -32,6 +35,31 @@ Installation
3235

3336
And you're done!
3437

38+
Cached Auth Preprocessor
39+
------------------------
40+
41+
Sometimes you want to preprocess to ``User`` instance before storing
42+
it into cache. ``cached_auth`` allows you to define
43+
``settings.CACHED_AUTH_PREPROCESSOR``, a callable that takes two arguments, ``user`` & ``request`` and returns a ``User`` instance.
44+
45+
A classic example of this would be to attach ``Profile`` data
46+
to ``User`` object so calling ``request.user.profile`` does not incur a
47+
database hit. Here's how we can implement it.
48+
49+
```python
50+
51+
def attach_profile(user, request):
52+
try:
53+
user.get_profile()
54+
# Handle exception for user with no profile and AnonymousUser
55+
except (Profile.DoesNotExist, AttributeError):
56+
pass
57+
58+
59+
# In settings.py:
60+
CACHED_AUTH_PREPROCESSOR = 'path.to.module.attach_profile'
61+
```
62+
3563
Running Tests
3664
-------------
3765

@@ -46,6 +74,12 @@ To run the test suite with Django custom user (this will run only on Django 1.5)
4674
Changelog
4775
---------
4876

77+
Version 0.2.0
78+
=============
79+
80+
* Added support for Django 1.5's customer user model
81+
* Added ``CACHED_AUTH_PREPROCESSOR`` setting
82+
4983
Version 0.1.1
5084
=============
5185

0 commit comments

Comments
 (0)