Getting ready

There are several things to do in order to prepare caching for your Django project. First, let's examine how this would be done for a virtual environment project:

  1. Install the memcached server, as follows:
$ wget http://memcached.org/files/memcached-1.5.7.tar.gz
$ tar -zxvf memcached-1.4.23.tar.gz
$ cd memcached-1.4.23
$ ./configure && make && make test && sudo make install
  1. Start the memcached server, as shown in the following:
$ memcached -d
  1. Install Memcached Python bindings in your virtual environment, as follows:
(myproject_env)$ pip3 install python-memcached~=1.59.0

If using a Docker environment, follow these steps instead:

  1. Update your docker-compose.yml file to associate a Memcached container with your app, as in the following:
# docker-compose.yml
version: '3'
services:
# ...
memcached:
image: 'memcached:1.5'
app:
# ...
environment:
# ...
- "CACHE_LOCATION=memcached:11211"
  1. Include the Memcached Python bindings in the requirements for your app container, like so:
# requirements.txt or requirements/base.txt
# ...
python-memcached~=1.59.0
  1. Stop, build, and restart your containers.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.222.125.171