Memcached does not work on local machine | Docker

52 Views Asked by At

What is the whole point? In our Yii2 project we have memcached, which works successfully in production. But either it doesn’t work well on a local computer, or it doesn’t save any data in its storage.

In general, the situation is like this. In one view I collect data via JS about executed AJAX methods. I save or supplement them by key in the cache. But when I try to get the data in the config in 'on beforeAction' - the output is false. Although, if you display data on the same page using the key, everything is found and displayed.

docker-compose.yml:

  memcached:
    image: memcached:1.6.22
    network_mode: bridge
    entrypoint:
      - memcached
      - -m 5120
      - -I 25m
    restart: always

common/config/main.php:

'cache' => [
    'class' => 'yii\caching\MemCache',
    'useMemcached' => true,
    'servers' => [
        [
            'host' => 'memcached',
            'port' => 11211,
            'weight' => 60,
        ],
    ],
],

What did I try to do?

I tried to increase the amount of shared storage. And also storage for 1 memory cell. It gave no results, either individually or together. Changed according to the free space of my work machine

Log in memcached: Set:

28: going from conn_nread to conn_new_cmd
2024-01-23T08:09:56.506557294Z 28: going from conn_new_cmd to conn_mwrite
2024-01-23T08:09:56.506558794Z 28: going from conn_mwrite to conn_new_cmd
2024-01-23T08:09:56.506560377Z 28: going from conn_new_cmd to conn_waiting
2024-01-23T08:09:56.506561877Z 28: going from conn_waiting to conn_read
2024-01-23T08:09:56.512049919Z 28: going from conn_read to conn_parse_cmd
2024-01-23T08:09:56.512059252Z <28 set test 0 0 20
2024-01-23T08:09:56.512060877Z 28: going from conn_parse_cmd to conn_nread
2024-01-23T08:09:56.512062461Z > NOT FOUND test
2024-01-23T08:09:56.512063919Z >28 STORED

Get:

28: going from conn_nread to conn_new_cmd
2024-01-23T08:10:22.920333209Z 28: going from conn_new_cmd to conn_mwrite
2024-01-23T08:10:22.920404834Z 28: going from conn_mwrite to conn_new_cmd
2024-01-23T08:10:22.920409792Z 28: going from conn_new_cmd to conn_waiting
2024-01-23T08:10:22.920411376Z 28: going from conn_waiting to conn_read
2024-01-23T08:10:22.920976376Z 28: going from conn_read to conn_parse_cmd
2024-01-23T08:10:22.920982209Z <28 get test
2024-01-23T08:10:22.920983917Z > NOT FOUND test
2024-01-23T08:10:22.920985959Z >28 END
1

There are 1 best solutions below

0
Павел Осипов On

The issue is resolved. It turned out that the problem was not related to memcached. The issue was that another developer was doing a forced cleanup every time the page was loaded