zoukankan      html  css  js  c++  java
  • Kahana::Cache

    大致的调用方法请参考 AUTH模块

    缓存最简单的是文件缓存:

    举个最简单的例子:

    先配置好cache 配置文件:

     1 <?php defined('SYSPATH') or die('No direct script access.');
     2 return array
     3 (
     4     'memcache' => array(
     5         'driver'             => 'memcache',
     6         'default_expire'     => 3600,
     7         'compression'        => FALSE,              // Use Zlib compression (can cause issues with integers)
     8         'servers'            => array(
     9             'local' => array(
    10                 'host'             => 'localhost',  // Memcache Server
    11                 'port'             => 11211,        // Memcache port number
    12                 'persistent'       => FALSE,        // Persistent connection
    13                 'weight'           => 1,
    14                 'timeout'          => 1,
    15                 'retry_interval'   => 15,
    16                 'status'           => TRUE,
    17             ),
    18         ),
    19         'instant_death'      => TRUE,               // Take server offline immediately on first fail (no retry)
    20     ),
    21     'memcachetag' => array(
    22         'driver'             => 'memcachetag',
    23         'default_expire'     => 3600,
    24         'compression'        => FALSE,              // Use Zlib compression (can cause issues with integers)
    25         'servers'            => array(
    26             'local' => array(
    27                 'host'             => 'localhost',  // Memcache Server
    28                 'port'             => 11211,        // Memcache port number
    29                 'persistent'       => FALSE,        // Persistent connection
    30                 'weight'           => 1,
    31                 'timeout'          => 1,
    32                 'retry_interval'   => 15,
    33                 'status'           => TRUE,
    34             ),
    35         ),
    36         'instant_death'      => TRUE,
    37     ),
    38     'apc'      => array(
    39         'driver'             => 'apc',
    40         'default_expire'     => 3600,
    41     ),
    42     'wincache' => array(
    43         'driver'             => 'wincache',
    44         'default_expire'     => 3600,
    45     ),
    46     'sqlite'   => array(
    47         'driver'             => 'sqlite',
    48         'default_expire'     => 3600,
    49         'database'           => APPPATH.'cache/kohana-cache.sql3',
    50         'schema'             => 'CREATE TABLE caches(id VARCHAR(127) PRIMARY KEY, tags VARCHAR(255), expiration INTEGER, cache TEXT)',
    51     ),
    52     'eaccelerator'           => array(
    53         'driver'             => 'eaccelerator',
    54     ),
    55     'xcache'   => array(
    56         'driver'             => 'xcache',
    57         'default_expire'     => 3600,
    58     ),
    59     'file'    => array(
    60         'driver'             => 'file',
    61         'cache_dir'          => APPPATH.'cache',
    62         'default_expire'     => 3600,
    63         'ignore_on_delete'   => array(
    64             '.gitignore',
    65             '.git',
    66             '.svn'
    67         )
    68     )
    69 );
    config

    然后

    1         $cache=Cache::instance('file');        
    2         $arr=array(1,2,3,4,51,2,3,3,6,8,9,0);
    3         //$cache->set(1,$arr);     //添加缓存;
    4         print_r($cache->get(1));  //获取缓存;

    将数据存储到sqlite中:

    首先确保你的系统有没有安装sqlite3和 php-sqlite,如果没有 apt-get安装并重启apache。

    使用方法和文件一样,只有初始化方法不同:

    $cache=Cache::instance('sqlite'); 
  • 相关阅读:
    treeview(树加载)
    9.SQL存储过程实例详解
    面向对象之封装
    cookie和session
    自定义web框架
    IO多路复用
    协程
    concurrent.futures模块(进程池/线程池)
    死锁与递归锁及信号量等
    并发编程之多线程
  • 原文地址:https://www.cnblogs.com/canbefree/p/3836297.html
Copyright © 2011-2022 走看看