Login

Tag "cache"

Snippet List

Cached Del.icio.us API Calls

This will save your del.icio.us bookmarks in your own database with a Bookmarks model. It depends on several things: 1. `DELICIOUS_USER` and `DELICIOUS_PASS` defined in settings.py 2. [pydelicious](http://code.google.com/p/pydelicious/) installed 3. Any view that uses del.icio.us should call the delicious() function, to update the database. 4. The [cache_function](http://www.djangosnippets.org/snippets/109/) decorator must be available. (I have it in a decorators.py file in my app; if you move it, you need to update the import) 5. The [django-tagging](http://code.google.com/p/django-tagging/) app, although it could be modified to not need this rather easily. Other than all those dependencies, it's actually rather simple. It will call del.icio.us for the 5 most recent posts, and create them if they're not already in the database. Otherwise, it'll check for updates, and change as appropriate. It won't return anything, as it updates the models themselves.

  • cache
  • delicious
  • pydelicious
  • api
  • bookmarks
Read More

Cache Any Function

A decorator similar to `cache_page`, which will cache any function for any amount of time using the Django cache API. I use this to cache API calls to remote services like Flickr in my view, to prevent having to hit their servers on every request. I posted a sample function which uses the [delicious API](http://www.djangosnippets.org/snippets/110/) in the function, also. **Update**: It now also will put in a temporary 'in-process' variable (an instance of `MethodNotFinishedError`) in the cache while the function is processing. This will prevent the cache from calling the method again if it's still processing. This does not affect anything **unless you're using threads**.

  • cache
  • function
  • threading
  • threads
  • thread
Read More

Memcache Status

I use this script to keep track of the cache usage for various sites. It presently only supports memcached because that's all that I use, but leave a comment with patches for other systems and I'll add them.

  • memcache
  • cache
  • status
Read More

78 snippets posted so far.