can I store objects in the servers memory to cache data using django, 开发者_开发知识库or do I have to use memcache for that?
There are a variety of options, including using the server's memory:
- Memcached
- Database caching
- Filesystem caching
- Local-memory caching
- Dummy caching (for development)
- Using a custom cache backend
To use the server's memory, in settings.py
, you should set the cache backend as follows:
CACHE_BACKEND = 'locmem://'
See the following page in the Django documentation for further information on the various cache backends and for details on how to enable caching: http://docs.djangoproject.com/en/dev/topics/cache/
Django does allow many types of caching such as file system and local memory caching. In local memory caching, each process has its own private cache instance, which means no cross-process caching is possible because they exist in different virtual memories. Hence, local memory caching is not efficient for production environments.
Memcache is preferable because it solves that problem and is really fast as it runs on RAM. Django admits that Memcache is fastest on its website.
Memcache is also free and easy to install (sudo apt-get install memcached). You also need something to bind python to Memcache such as python-memcached.
精彩评论