Управление кэшем в проекте PHP
In the process of client requesting PHP page from server, server is controllable. Controllable can be optimized, the focus of optimization is cache optimization. Imagine? Data is stored in DB, access to DB requires reading hard disk data, but if you need data speed > maximum read and write speed of hard disk. There will be IO bottlenecks. Then, use memory to cache the data result set so that the user can read the cache first and read from DB if not. In this way, the speed of data response can be improved and the data source can be protected. Although PHP opens shmop extensions to manage memory, the size of memory it can manage is limited. Only NOSQL which is very popular: Memcache High Performance Distributed Memory Cache Server (Distributed configuration: 1. There are multiple Memcache servers; 2. Open the corresponding extension of php, which can be achieved by addServer (). The underlying layer identifies the server by hash redundancy of key, so in code implementation, do not change the order of servers before accessing, otherwise, it may not get the value. Redis High Performance Memory Cache Server Master-slave configuration: master master master server performs modification operations, multiple slaves (read-only) connect master, incrementally update data to itself after the first full replication. If slave breaks, the master will be automatically replicated in full when reconnected)
MEMCACHE
- Хранить в режиме ключ-значение
- Ключ может достигать 250B, значение может достигать 1 м
Значение хранится в виде строки:
- Время истечения срока действия товара-это отметка времени, неограниченная; в sun оно не может превышать 30 дней секунд
- Не настойчивый Что нам нужно, так это скорость.
Вопросы, требующие внимания
∧
memcache и redis Самая большая разница заключается в Сохраняемости (то есть в том, могут ли данные быть сохранены на жестком диске). redis Из-за своей разнообразной структуры данных он отвечает большему количеству бизнес-потребностей, но memcache Скорость чтения выше.
∨
РЕДИС
Поддержка расширенных структур данных (здесь не обсуждается)
- Значение может достигать 512 м
Настойчивость :
- Сохранение моментальных снимков (МОМЕНТАЛЬНАЯ съемка) Определенное количество ключевых изменений за определенный период времени приведет к полной репликации данных управления памятью redis на жесткий диск.
- Точная сохраняемость (OF) Используется для сохранения каждой выполняемой команды. После открытия сохраняйте каждую секунду. См. Аннотации на английском языке на рисунке ниже.
Вопросы, требующие внимания