定制 laurent22/kache 二次开发

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

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

laurent22/kache

Composer 安装命令:

composer require laurent22/kache

包简介

Simple cache system with support for multiple drivers.

README 文档

README

A simple cache system with support for multiple drivers and a focus on performance. There is only a minimal wrapper between the exposed API and the underlying driver so as to keep the library as fast as possible.

Installation

Either checkout the code and require src/Kache.php. Or use Composer:

"require": { "laurent22/kache": "1.*" }

Setup

Using the file driver:

Kache::setup(array(
	'driver' => 'file',
	'path' => '/path/to/cache_folder',
));

Using the Redis driver:

Kache::setup(array(
	'driver' => 'redis',
	'server' => array(
		'host' => '127.0.0.1',
		'port' => 6379,
		'dbindex' => 1,
	),
));

Using the null driver (to disable caching):

Kache::setup(array(
	'driver' => 'null',
));

Usage

The class instance can be accessed either via Konfig::instance() or by the convenience method k(). For example:

k()->set('somekey', 'somevalue', 120); // Cache for 2 minutes
var_dump(k()->get('somekey'));
$k()->delete('somekey');

You may also use the getOrRun() method which will either return the given key or, if it doesn't exist, will do the following:

  • run the provided function.
  • set the key to the value returned by the function. This allows simplifying the boiler plate code needed when getting/setting cache values. For example, the following code:
function getName() {
	$name = k()->get('name');
	if ($name !== null) return $name;
	$name = getNameFromDb();
	k()->set('name', $name, 600);
	return $name;
}

can be simplified to just this:

function getName() {
	return k()->getOrRun('name', function() {
		return getNameFromDb();
	}, 600);
}

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-02-16

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固