]> BookStack Code Mirror - website/blob - content/docs/admin/cache-session-config.md
Improved code highlighting using codemirror
[website] / content / docs / admin / cache-session-config.md
1 +++
2 title = "Cache & Session Configuration"
3 description = "Cache & Session setup with details for redis and memcached"
4 date = "2017-01-01"
5 type = "admin-docs"
6 +++
7
8 By default BookStack will use a file system cache that's storage in the `storage/framework` folder. This is also used to store user session data. Below are some alternative systems that can be used for caching & sessions.
9
10 ### Database
11
12 As an easy alternative to using the filesystem, you can use the database to store the cache and session. The database setup for this is done when installing/updating BookStack so you simply need to set the following in your `.env` file:
13
14 ```bash
15 CACHE_DRIVER=database
16 SESSION_DRIVER=database
17 ```
18
19 ### Memcached
20
21 To use memcached for caching and/or sessions open up your `.env` file and find the `CACHE_DRIVER` & `SESSION_DRIVER` variables. By default these are both set to `file`. Change these variables to `memcached`. You will also need to add a variable to specify the memcached servers you are using. To do this add a variable named `MEMCACHED_SERVERS` to the `.env` file and set the value to be your memcached servers in the following format: `HOST:PORT:WEIGHT,HOST2:PORT:WEIGHT`. You can specify as many servers as you want. Their usage split will be determined by the weight given to them. Here are some examples of what the `.env` file should look like:
22
23 ```bash
24 # Set both the cache and session to use memcached
25 CACHE_DRIVER=memcached
26 SESSION_DRIVER=memcached
27
28 # Example of using a single local memcached server
29 MEMCACHED_SERVERS=127.0.0.1:11211:100
30
31 # Example of using two non-local memcached servers with an equal split
32 MEMCACHED_SERVERS=8.8.8.8:11211:50,8.8.4.4:11211:50
33 ```
34
35 ### Redis
36
37 To use Redis for caching and/or sessions open up your `.env` file and find the `CACHE_DRIVER` & `SESSION_DRIVER` variables. By default these are both set to `file`. Change these variables to `redis`. You will need to add a variable to specify your Redis servers. To do this add a variable named `REDIS_SERVERS` to the `.env` file and set the value to point at your Redis servers in the following format: `HOST:PORT:DATABASE,HOST2:PORT:DATABASE`. The default values for each host are `127.0.0.1:6379:0`. You can list as many servers as you like.  
38
39 To specify if you would like to cluster you Redis servers create a `REDIS_CLUSTER` key in the `.env` file and set it to `true`. This option, if set to true, will instruct the built-in Redis client to perform client-side sharding across your Redis nodes, allowing them to pool together for a large amount of RAM. This disadvantage of this it that it does not allow for fail-over.
40
41 Here's an example of setting the Redis configuration:
42
43 ```bash
44 # Set both the cache and session to use Redis
45 CACHE_DRIVER=redis
46 SESSION_DRIVER=redis
47
48 # Example of using a single local Redis server
49 REDIS_SERVERS=127.0.0.1:6379:0
50
51 # Example of using two non-local Redis servers clustered together
52 REDIS_SERVERS=8.8.8.8:6379:0,8.8.4.4:6379:0
53 REDIS_CLUSTER=true
54 ```