smart-php/super-cache
Composer 安装命令:
composer require smart-php/super-cache
包简介
Simple PHP cache mechanism which is 500X Faster Caching than Redis/Memcache/APC in PHP & HHVM
README 文档
README
Simple PHP cache mechanism which provides 200X Faster Caching than other PHP cache mechanisms like Redis/Memcache/APC in PHP & HHVM. SuperCache uses the normal file system to store values. This method is faster than Redis/Memcache because all those serialize and unserialize objects.
Installation
Via Composer
composer require smart-php/super-cache
Basic Usage
<?php require __DIR__.'/vendor/autoload.php'; use SuperCache\SuperCache as sCache; //Saving cache value with a key // sCache::cache('<key>')->set('<value>'); sCache::cache('myKey')->set('Key_value'); //Retrieving cache value with a key echo sCache::cache('myKey')->get(); ?>
Cache Folder
By default the cache will save in the tmp folder. Please make sure that the tmp folder has write access.
You can set a custom folder for the cache:
sCache::setPath('youfolder/tempfolder/');
or
define('SuperCache_PATH','youfolder/tempfolder/');
Advanced Options
Locking
Lock your data to readonly so that the data won't be overwritten.
sCache::cache('myKey')->set('my_value')->lock(); //setting new value sCache::cache('myKey')->set('new_value'); echo sCache::cache('myKey')->get(); //output : my_value //unlocking sCache::cache('myKey')->unlock()->set('new_value'); echo sCache::cache('myKey')->get(); //output : new_value
Options
//options sCache::cache('myKey')->set('my_value')->options([ 'expiry' => time()+600, //time to expire 'lock' => true //alternative method to lock or unlock 'custom' => 'your customer attribute value' ]); //isValid (To check for a valid key or to check whether it has expired or not) sCache::cache('myKey')->isValid(); //true or false //To get all option values print_r(sCache::cache('myKey')->getOptions()); //array //destroy sCache::cache('myKey')->destroy(); //clearAll (Clear all cache values) sCache::cache('myKey')->clearAll();
Cache Your Class
You can cache any class to super cache. To bind data you need to use the trait class State by adding use State, or you can do it via your custom set_state.
use SuperCache\SuperCache as sCache; use SuperCache\State as State; sCache::setPath('youCacheLocation'); Class MyClass { /** * This trait class will bind data from cache to your class */ use State; private $firstName; private $lastName; public function setName($firstName, $lastName) { $this->firstName = $firstName; $this->lastName = $lastName; } public function getName() { return $this->firstName . " ". $this->lastName; } } // Creating Object of your class $myObject = new MyClass; $myObject->setName("John", "Doe"); // Saving your object in SuperCache sCache::cache('myObject')->set($myObject); // Retrieving your object from Cache $cacheObject = sCache::cache('myObject')->get(); echo $myObject->getName();
License
The MIT License (MIT). Please see License File for more information.
smart-php/super-cache 适用场景与选型建议
smart-php/super-cache 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 888 次下载、GitHub Stars 达 22, 最近一次更新时间为 2018 年 06 月 10 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「cache」 「lightweight」 「caching」 「powerful」 「php-cache」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 smart-php/super-cache 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 smart-php/super-cache 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 smart-php/super-cache 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
repository php library
Laravel 5 - Repositories to the database layer
Splot Framework. Lightweight, fully featured framework for rapid web development.
Rinvex Repository is a simple, intuitive, and smart implementation of Active Repository with extremely flexible & granular caching system for Laravel, used to abstract the data layer, making applications more flexible to maintain.
Laravel 5 - Repositories to the database layer
Alfabank REST API integration
统计信息
- 总下载量: 888
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 22
- 点击次数: 26
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-06-10