Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to use Memcache with symfony

I using symfony 2 and I want to use Memcache with it but the problem is I can't find any explain for Memcache I just found for memcached so are they the same setup steps ? I added this lines to install Memcache on symfony?

config.yml

framework:
  session:
    handler_id: session.handler.memcached

for parameters.yml

parameters:   
  memcached_host: 127.0.0.1
  memcached_port: 11211
  memcached_prefix: custom_key_
  memcached_expire: 14400

services.yml

services:
  session.handler.memcached:
    class: Symfony\Component\HttpFoundation\Session\Storage\Handler\MemcachedSessionHandler
    arguments: [ "@session.memcached", { prefix: '%memcached_prefix%', expiretime: '%memcached_expire%' } ]


services:
  session.memcached:
    class: Memcached
    arguments:
      persistent_id: %memcached_prefix%
    calls:
      - [ addServer, [ %memcached_host%, %memcached_port% ]]



services:
  session.memcached:
    class: Madisoft\AppBundle\Utils\MemcachedWrapper
    arguments:
      persistent_id: '%memcached_prefix%'
    calls:
      - [ addServer, [ '%memcached_host%', '%memcached_port%' ] ]
like image 470
mrsharko Avatar asked Mar 25 '17 09:03

mrsharko


People also ask

What happens when memcache is full?

First, when memcached gets full, it will start removing items from the cache using the Least Recently Used algorithm. Second, you can have multiple instances of memcached running, adding them gets complicated because it will change the hashing algorithm used to determine which cache the data is in.

How does memcache store data?

How does Memcached work? Unlike databases that store data on disk or SSDs, Memcached keeps its data in memory. By eliminating the need to access disks, in-memory key-value stores such as Memcached avoid seek time delays and can access data in microseconds.

What is cache in Symfony?

The Cache component provides features covering simple to advanced caching needs. It natively implements PSR-6 and the Cache Contracts for greatest interoperability. It is designed for performance and resiliency, ships with ready to use adapters for the most common caching backends.


1 Answers

There is only one Memcached software, and it's the one available at https://memcached.org/.

There are two well-known PHP libraries for Memcached, called memcache (http://php.net/manual/en/book.memcache.php) and memcached (http://php.net/manual/en/book.memcached.php), so this is probably where your confusion comes from.

To use Memcached with Symfony 2 I suggest to use an external bundle by LeaseWeb which provides all the required documentation: https://github.com/LeaseWeb/LswMemcacheBundle.

Starting with Symfony 3.3 there will be a native Memcached adapter: see http://symfony.com/blog/new-in-symfony-3-3-memcached-cache-adapter.

like image 196
Francesco Abeni Avatar answered Sep 21 '22 04:09

Francesco Abeni