首页 > 编程语言 >PHP Cache_Lite 下载及使用

PHP Cache_Lite 下载及使用

时间:2023-02-17 16:56:52浏览次数:47  
标签:function Cache get cache time Lite PHP


https://github.com/pear/Cache_Lite


composer require pear/cache_lite

composer如果提示root不安全 可以切换为www用户 su - www -s /bin/bash


composer加载原理,有空再研究

http://bazingafeng.com/2016/10/27/composer-introduction/



自动加载有问题,我就把vendor/pear/cache_lite/ 下面的Cache目录单独拷贝出来使用


包含路径需要注意一下


<?php

//require ('vendor/autoload.php');
// Include the package
require_once('Cache/Lite/Function.php');


function get_time()
{
            return date("H:i:s", mktime());
}

// Set a id for this cache
$id = '123';

// Set a few options
$options = array(
     'cacheDir' => '/tmp/',
     'lifeTime' => 3
);

$objCache = new Cache_Lite_Function($options);

// cache the call to the get_time() function
// if return value is present in cache,
// Cache_Lite_Function will fetch it from the cache
// else the function will be called and the result returned
$time = $objCache->call('get_time');

echo "The cached time is " . $time . ". The real time is " . get_time();




标签:function,Cache,get,cache,time,Lite,PHP
From: https://www.cnblogs.com/cute/p/17130771.html

相关文章