Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A way to flush the template cache / remove old files #158

Closed
defcube opened this issue Nov 11, 2011 · 7 comments
Closed

A way to flush the template cache / remove old files #158

defcube opened this issue Nov 11, 2011 · 7 comments

Comments

@defcube
Copy link

defcube commented Nov 11, 2011

I had several old cache files on disk that I wanted to clean up. The problem is that the templatetag_cachekey remembers the path of the old compressed .js.

Short of flushing all of my memcache keys, is there a way to flush just the compressor templatetag keys?

@jezdez
Copy link
Member

jezdez commented Nov 24, 2011

There is no effective way to select all cache keys of django_compressor (although you could iterate over all keys and look for those that start with the default prefix django_compressor..

Instead I would suggest to use Django's ability to handle multiple cache backends, as mentioned in the docs

Simply set your COMPRESS_CACHE_BACKEND setting to a different backend than your "default" and you can easily clear it with the clear method as described here: https://docs.djangoproject.com/en/dev/topics/cache/#the-low-level-cache-api

EDIT: Getting to the backend is as easy as importing django.core.cache.get_cache and using it like this:

 my_special_cache = get_cache(settings.COMPRESS_CACHE_BACKEND)
 my_special_cache.clear()

@jezdez jezdez closed this as completed Nov 24, 2011
@jezdez
Copy link
Member

jezdez commented Nov 24, 2011

Ah, another thing you can try is the mtime_cache management command with the --clean option. Although that'll only delete the mtime cache, not the offline cache.

@defcube
Copy link
Author

defcube commented Nov 30, 2011

Thanks for the suggestions. I think using a separate cache for this is the easiest solution for me.

I have tried the mtime_cache management command, but as you said it doesn't clear the offline cache.

@jbranc
Copy link

jbranc commented Jan 6, 2014

certainly would be nice to not have to host a separate cache instance just for this. it seems quite common for compressor to get out of sync between cache and file system (i.e. if you delete the CACHE directory on disk, it will forever not work until you clear the cache). paying for a separate cache server or wiping the entire existing cache are't quite as good as a simple reset command for compressor

@ivensrocha
Copy link

Does anybody knows if there is a clear cache command at this moment? How to make django-compressor begin to compress files all over again, setting new keys into the cache, since the cache files were deleted?

@Alcolo47
Copy link

I don't know any such python or management command but if you use the
default COMPRESS_STORAGE (ie file storage), You can use:

python: shutil.rmtree(os.path.join(settings.STATIC_ROOT,
settings.COMPRESS_OUTPUT_DIR))
sh: rm -rf $STATIC_ROOT/$COMPRESS_OUTPUT_DIR # (I add a mistake to
prevent from stupid copy/paste consequence.)

2015-11-19 13:04 GMT+01:00 Ivens Rocha notifications@github.com:

Does anybody knows if there is a clear cache command at this moment? How
to make django-compressor begin to compress files all over again, setting
new keys into the cache, since the cache files were deleted?


Reply to this email directly or view it on GitHub
#158 (comment)
.

@julianklotz
Copy link

This one is old, but here are some notes:

  • Clearing the cache directory (either its contents or the directory itself) didn't do the job for me
  • What works for me is clearing the contents of the static folder like cd /data/static; rm -rf . (don’t copy-paste this, rm -rf is dangerous)
  • Then run ./manage.py collectstatic
  • If you use offline compression, run ./manage.py compress

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants