xes/cacher
Composer 安装命令:
composer require xes/cacher
包简介
Simple file caching for PHP with string replacements
README 文档
README
Cacher provides a simple caching functionality, usable with two lines of code.
Installation
Add "xes/cacher": "dev-master" to your composer.json file.
Usage
Before any HTML is output:
<?php $cache = new xes\Cacher('/path/to/cache/folder'); $cache->start(); ?>
The path must already exist and be writable by the web server.
At the end of your script:
<?php $cache->finish(); ?>
String replacements
For content such as page title and meta descriptions, you may not know the values until later in the script. For this there is a replacement method in Cacher:
<title><!--TITLE--></title> <?php $cache->setReplacements( array( "<!--TITLE-->" => $pageTitleFromDatabase, "<!--SOMETHINGELSE-->" => $somethingElse )); ?>
This simply performs a find-and-replace on the HTML until the search text doesn't exist.
The replacements array can also be passed directly to finish().
Settings
setEnabled(true/false) - choose if the cache should run or not. Useful for development environments.
setFolder(path) - absolute path to the cache folder. Must be writable by web server.
setTimeout(numberOfSeconds) - how many seconds should elapse until a cached file should be considered invalid.
setSuffix(fileSuffix) - the file suffix appended to all cache files. .cache.html by default.
setReplacements(array) - associative array of replacements in the format "find" -> "replace"
统计信息
- 总下载量: 78
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2015-02-17