From f6e0033aaeac6a68db81f4dafa623af7a79b59c7 Mon Sep 17 00:00:00 2001 From: Tino de Bruijn Date: Fri, 20 Feb 2015 17:58:53 +0100 Subject: [PATCH] Add note about usage of optimistic strategy with async backend --- docs/caching.rst | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/docs/caching.rst b/docs/caching.rst index dfb2dd3..6aa7a1e 100644 --- a/docs/caching.rst +++ b/docs/caching.rst @@ -132,7 +132,7 @@ As mentioned above, image generation is normally done synchronously. through the default cache file backend. However, you can also take advantage of deferred generation. In order to do this, you'll need to do two things: -1) install `django-celery`__ +1) install `celery`__ (or `django-celery`__ if you are bound to Celery<3.1) 2) tell ImageKit to use the async cachefile backend. To do this for all specs, set the ``IMAGEKIT_DEFAULT_CACHEFILE_BACKEND`` in your settings @@ -164,8 +164,23 @@ Or, in Python: else: url = '/path/to/placeholder.jpg' +.. note:: + + If you are using an "async" backend in combination with the "optimistic" + cache file strategy (see `Removing Safeguards`_ below), checking for + thruthiness as described above will not work. The "optimistic" backend is + very optimistic so to say, and removes the check. Create and use the + following strategy to a) have images only created on save, and b) retain + the ability to check whether the images have already been created:: + + class ImagekitOnSaveStrategy(object): + def on_source_saved(self, file): + file.generate() + + __ https://pypi.python.org/pypi/django-celery +__ http://www.celeryproject.org Removing Safeguards