raorsa/rw-file-cache
Composer 安装命令:
composer require raorsa/rw-file-cache
包简介
RW File Cache is a PHP File-based Caching Library. Its syntax is designed to closely resemble the PHP memcache extension.
README 文档
README
RW File Cache is a PHP File-based Caching Library.
Its syntax is designed to closely resemble the PHP memcache extension.
Installation
You can easily install with composer. Just run composer require rapidwebltd/rw-file-cache.
If you are using Laravel, consider using the Laravel Cache Driver for RW File Cache instead.
Usage
This section will show you how to use RW File Cache. If you have used memcache before, this should be pretty familiar.
Setup & Configuration
Before you can do anything with RW File Cache, you must instantiate it and then, if you wish, set some configuration options.
require_once "vendor/autoload.php"; $cache = new \rapidweb\RWFileCache\RWFileCache(); $cache->changeConfig(["cacheDirectory" => "/tmp/rwFileCacheStorage/"]);
This code creates a new RW File Cache object called $cache and then configures it to store its cache files in the /tmp/rwFileCacheStorage/ directory.
There are several different configuration variables you can override. The table below describes them.
| Option | Description | Default |
|---|---|---|
cacheDirectory |
The directory in which you wish the cache files to be stored. We recommend you change this to a site-specific directory and ensure it is outside of the web root. You must include a trailing slash. | /tmp/rwFileCacheStorage/ |
gzipCompression |
Whether or not to compress cache files using gzip. Unless you are storing very small values in your cache files, we recommend you leave this enabled. | true |
fileExtension |
The file extension that will be appended to all your cache files. | cache |
unixLoadUpperThreshold |
If your server's load is greater than this value, cache files will be returned regardless of whether they have expired. This can be used to prevent cache files being regenerated when server load is high. If you do not wish to use this feature, set this option to -1. |
4.00 |
Setting a cache item
Putting something in your file cache is easy. You just need to use the set method, as shown below.
$cache->set('nursery_rhyme',"Mary had a little lamb", strtotime('+ 1 day'));
The first parameter is the cache key, which uniquely references this cache item.
The second parameter is the cache value - what you wish to store in this cache item. This can be a string, integer, array, object or any type of serializable PHP variable.
The third paramter is the expiry time. It can be specified as a UNIX timestamp or as a number of seconds less than 30 days worth. Cache items will expire and not be retrievable when this time is reached.
Note that if you use dots, dashes, underscores or a few other special characters in your cache key, the created cache files will be put into a directory structure. For example, a cache key of objects.cars.redCar will be stored in objects/cars/redCar.cache. This is useful if you wish to categorise cache files and to prevent too many cache files building up in a single directory.
Getting a cache item
To get a cache item you've previously stored, you need to use the get method. An example of how to do this is shown below.
$var = $cache->get('nursery_rhyme');
The only parameter is the cache key you defined when setting the cache item. You can retrieve any cached variable in this way.
Other RW File Cache methods
The setting and retrieval of cache items are the most important parts of RW File Cache. In fact, the set and get methods are probably all you will need.
However, the library provides the following more advanced commands if you need them.
$cache->delete($key)- Delete a specific item from the cache.$cache->flush()- Deletes all items from the cache.$cache->replace($key, $content, $expiry)- Similar to thesetmethod, but will only update a cache item's value if the cache item already exists.$cache->increment($key, $offset)- Increment a numeric cache item value by the specified offset (or one if the offset is omitted).$cache->decrement($key, $offset)- Decrements a numeric cache item value by the specified offset (or one if the offset is omitted).
raorsa/rw-file-cache 适用场景与选型建议
raorsa/rw-file-cache 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 41 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 05 月 13 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「cache」 「library」 「caching」 「file cache」 「caching library」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 raorsa/rw-file-cache 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 raorsa/rw-file-cache 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 raorsa/rw-file-cache 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
repository php library
Laravel 5 - Repositories to the database layer
Inbox pattern process implementation for your Laravel Applications
Core library that defines common interfaces used by the rest of the intahwebz..
Amqp classes
Provides command to manage a web library directory
统计信息
- 总下载量: 41
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 20
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: LGPL-3.0-only
- 更新时间: 2024-05-13