Use memcached for session storage
- Topics:
- Configuration
- Cache
- Storage
CREATED FOR:
- Experienced
- Admin
- Developer
Memcached is a general-purpose, distributed memory caching system. It is often used to speed up dynamic database-driven websites by caching data and objects in RAM to reduce the number of times an external data source (such as a database or API) must be read.
Memcached provides a large hash table that can be distributed across multiple machines. When the table is full, subsequent inserts cause older data to be purged in least recently used (LRU) order. The size of this hash table is often very large. (Source: memcached.org)
Commerce uses memcached for session storage but not for page caching. For page caching, we recommend Redis or Varnish.
To configure Commerce to use memcached:
-
Open
<your install dir>/app/etc/env.php
in a text editor. -
Locate the following:
'session' => array ( 'save' => 'files', ),
-
Change it as follows:
'session' => array ( 'save' => 'memcached', 'save_path' => '<memcache ip or host>:<memcache port>' ),
memcached has optional startup parameters that are beyond the scope of this guide. You can find more information about them in the memcached documentation, source code, and changelogs.
-
Continue with the next section.
To verify memcached works with Commerce:
-
Delete the contents of the following directories under your Commerce installation directory:
rm -rf var/cache/* var/page_cache/* var/session/*
-
Go to any page on the storefront.
-
Log in to the Admin and browse to several pages.
If no errors display, congratulations! memcached is working! You can optionally look at memcached storage as discussed in the next step.
If errors display (such as an HTTP 500 (Internal Server Error)), enable developer mode and diagnose the issue. Make sure that memcached is running, configured properly, and that
env.php
has no syntax errors. -
(Optional.) Use Telnet to look at memcached storage.
telnet <memcached host or ip> <memcached port>
stats items
The results display similar to the following:
STAT items:3:number 1 STAT items:3:age 7714 STAT items:3:evicted 0 STAT items:3:evicted_nonzero 0 STAT items:3:evicted_time 0 STAT items:3:outofmemory 0 STAT items:3:tailrepairs 0 [Look at the keys in more detail](https://darkcoding.net/software/memcached-list-all-keys/)
Commerce
- Overview
- General setup
- Deployment
- Cache
- Command Line
- Command-line tool
- Common commands
- Enable logging
- Manage the cache
- Manage indexers
- Configure cron jobs
- Compile code
- Operation mode
- Start message queue consumers
- URN highlighter
- Dependency reports
- Localization
- Configuration management
- Static view
- Create symlinks
- Run unit tests
- Convert layout files
- Generate data for performance testing
- Run support utilities (Commerce only)
- Configuration files
- Configuration paths
- Cron Jobs
- Logs
- Message Queues
- Multiple sites
- Search Engine
- Security
- Storage
- Return to Operational Guides