定制 libertyphp/apcu-cache 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

libertyphp/apcu-cache

Composer 安装命令:

composer require libertyphp/apcu-cache

包简介

The PSR-6 and PSR-16 cache implementation using APCu. The fastest cache for PHP.

README 文档

README

PSR-6 and PSR-16 cache implementation using APCu. APCu is an in-memory key-value store for PHP. Keys are of type string and values can be any PHP variables.

Why APCu Cache?

Network

APCu is non-distributed cache which you can use only in HTTP request (it doesn't work in PHP CLI). If you have a web application that doesn't run on different web servers it's better to use APCu cache, because it's the simplest cache without requests over the network.

Speed

APCu is faster than Memcached and Redis. Benchmark results of setting and getting of 10000 string values (Intel Core i5-8250U, DDR4 2400MHz):

APCu
set 0.01187s
get 0.00633s

Memcached
set 0.66142s
get 0.63786s

Redis
set 0.37687s
get 0.39227s

So, if your web application makes a lot of requests to the cache, it's better to have a warmed APCu cache on each worker.

Install

composer require libertyphp/apcu-cache

Docker configuration

If you use php-fpm docker add this code to install APCu in PHP:

ARG APCU_VERSION=5.1.21

RUN pecl install apcu-${APCU_VERSION} && docker-php-ext-enable apcu
RUN echo "apc.shm_size=1024M" >> /usr/local/etc/php/php.ini
RUN echo "apc.ttl=0" >> /usr/local/etc/php/php.ini
RUN echo "apc.gc_ttl=0" >> /usr/local/etc/php/php.ini

Using PSR-6 implementation

$cachePool = new ApcuCacheItemPool();
$cacheItem = (new ApcuCacheItem('u1030_rating', 98))
    ->expiresAfter(3600);

$cachePool->save($cacheItem);

Using PSR-16 implementation

$cache = new ApcuCache();
$cache->set('u1030_rating', 98, 3600);

Copyright

Copyright (c) 2022 Vladimir Lila. See LICENSE for details.

统计信息

  • 总下载量: 4.79k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 4
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-10-30

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固