定制 aloframework/cache 二次开发

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

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

aloframework/cache

最新稳定版本:2.0

Composer 安装命令:

composer require aloframework/cache

包简介

Dual-way Redis cache management

README 文档

README

Redis cache manager

Latest release API documentation: https://aloframework.github.io/cache/

License Latest Stable Version Total Downloads

dev-develop Latest release
Dev Build Status Release Build Status
Coverage Status Coverage Status

Installation

Installation is available via Composer:

composer require aloframework/cache

Usage

Only Redis is supported at this time.

<?php

    use AloFramework\Cache\Clients\RedisClient;

    $redis = new RedisClient();
    $redis->connect('localhost');

    $redis->setKey('foo', 'bar', 300); // expire the key in 5 minutes
    $redis->setKey('foo', 'bar', new DateTime('2015-01-01 05:05:05')); //Expire the key on 2015-01-01 05:05:05
    $redis->setKey('foo', 'bar'); //Use default expiration time
    $redis['foo'] = 'bar'; //Use default expiration time

    //Echo the keys
    echo $redis->getKey('foo');
    echo $redis['foo'];

    //Echo all the keys
    print_r($redis->getAll());

    //Loop through all the keys
    foreach ($redis as $k => $v) {
        echo 'Key: ' . $k . ', Value: ' . $v . '<br/>';
    }

    //Count the number of items in the database
    echo count($redis);

    //Or do anything you would with the standard Redis class - RedisClient extends it.

Alternative usage

<?php

    use AloFramework\Cache\Clients\RedisClient;
    use AloFramework\Cache\CacheItem;

    //Save an item
    $server = new RedisClient();
    $server->connect();

    $cacheItem           = new CacheItem('key', 'value', $server);
    $cacheItem->lifetime = 600;
    $cacheItem->saveToServer();

    // Get or load an item
    $cacheItem = new CacheItem('key');
    $cacheItem->getFromServer($server);

    echo $cacheItem->value;

Configuration

Configuration is done via the Configuration class.

  • Cfg::CFG_IP - default IP to use in the connect() method (defaults to 127.0.0.1)
  • Cfg::CFG_PORT - default port to use in the connect() method (defaults to 6379)
  • Cfg::CFG_TIMEOUT - default cache timeout (defaults to 300 seconds)

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2015-10-24