Skip to content

Winter Data Memcache: Memcached Client Module

Winter Data Memcache connects Winter Boot applications to Memcached servers. It supports both the memcached and memcache PHP extensions, each through its own template.

Install suvera/winter-modules as described in Installation, then enable the module in application.yml:

application.yml
modules:
- module: 'dev\winterframework\data\memcache\MemcacheModule'
enabled: true
configFile: memcache-config.yml

One of the two PHP Memcache client extensions is required — see Installation:

Define connections under memcache: (for the memcache extension) and/or memcached: (for the memcached extension). Each entry becomes a bean named after its name.

config/memcache-config.yml
# Used with the memcache extension -> MemcacheTemplate
memcache:
- name: bean01
idleTimeout: 30
timeout: 0
retry_interval: 0
status: 0
servers:
- host: 127.0.0.1
port: 11211
weight: 0
# Used with the memcached extension -> MemcachedTemplate
memcached:
- name: bean02
timeout: 0
idleTimeout: 30
retry_interval: 0
status: 0
servers:
- host: 127.0.0.1
port: 11211
weight: 0

Autowire each template by its bean name:

use dev\winterframework\data\memcache\mc\MemcacheTemplate;
use dev\winterframework\data\memcache\mcd\MemcachedTemplate;
use dev\winterframework\stereotype\Autowired;
#[Autowired("bean02")]
private MemcachedTemplate $memcached;
#[Autowired("bean01")]
private MemcacheTemplate $memcache;