Skip to content

Commit

Permalink
Merge pull request #144 from ccnmtl/custom-cache-clear-option
Browse files Browse the repository at this point in the history
Add custom cache clear option
  • Loading branch information
thraxil committed Sep 9, 2016
2 parents e688543 + 2fdf4de commit ba69f02
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
9 changes: 9 additions & 0 deletions docs/configuration.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Configuration
=============

.. configuration::

`PAGETREE_CUSTOM_CACHE_CLEAR`
Use this as a hook to clear any custom caches you've set up. It will
get called whenever Pagetree's internal cache is called. The function
should take one argument: the `Section` whose cache is getting cleared.
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ as possible.
:maxdepth: 2

installation
configuration
custom_pageblocks
api
testing
Expand Down
4 changes: 4 additions & 0 deletions pagetree/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@ def clear_caches(self):
cache.delete("pagetree.%d.is_last_child" % self.id)
cache.delete("pagetree.%d.get_edit_url" % self.id)

if hasattr(settings, 'PAGETREE_CUSTOM_CACHE_CLEAR') and \
callable(settings.PAGETREE_CUSTOM_CACHE_CLEAR):
settings.PAGETREE_CUSTOM_CACHE_CLEAR(self)

def clear_tree_cache(self):
depth_first_traversal = self.get_root().get_annotated_list()
for (s, ai) in depth_first_traversal:
Expand Down

0 comments on commit ba69f02

Please sign in to comment.