phalcon: 缓存片段,文件缓存,memcache缓存
几种缓存,需要用到前端配置,加后端实例配合着用
片段缓存:
public function indexAction()
{
//渲染页面
$this->view->setTemplateAfter('common'); //缓存片段
//前端配置
$frontcache = new \Phalcon\Cache\Frontend\Output(array(
"lifetime" => 86400
));
//后端处理
$cache = new \Phalcon\Cache\Backend\File($frontcache, array(
"cacheDir" => "../app/cache/"
));
//查询片段是否存在
$content = $cache->start("index.pthm");
if ($content == null) { echo date("r");
$this->view->pick("index/index"); //缓存片段
$cache->save(); } else {
echo $content;
} }
文件缓存:
public function lastAction()
{
//数据缓存
//前端配置
$frontcache = new \Phalcon\Cache\Frontend\Data(array(
"lifetime"=>86400
));
//后端实例
$cache = new \Phalcon\Cache\Backend\File($frontcache, array(
'cacheDir'=>'../app/cache/'
));
$cacheKey = 'customer_10';
$customer = $cache->get($cacheKey);
//在3600有效期内读取缓存
// $customer = $cache->get($cacheKey, 3600);
if($customer == null)
{
$customer = \SysCustomer::find(array(
"limit"=>10
))->toArray();
//保存缓存
$cache->save($cacheKey, $customer);
//单独设置缓存的有效期
// $cache->save($cacheKey, $customer,3600);
}
var_dump($customer);
}
注意:MainTask.php
如果你是命令行运行MainTask.php,在用文件缓存的时候,如果设置的是cacheDIR='/',以windows为例,我的php盘是f:\,那么生成的缓存文件在 f:\ 根目录下
memcache缓存,本例是windows下:
public function memcacheAction()
{
//memcache缓存
//前端配置有效期
$frontcache = new \Phalcon\Cache\Frontend\Data(array(
"lifetime"=>86400
));
//后端实例化
$memcache = new \Phalcon\Cache\Backend\Memcache($frontcache, array(
"servers" => array(
array(
"host" => "127.0.0.1",
"port" => "11211",
"weight" => "1"
)
)
)); $mydata = $memcache->get('my-data');
if($mydata == null) {
$mydata = array(1,2,3,4,5);
//保存缓存
$memcache->save('my-data', $mydata);
echo "--";
}
var_dump($mydata); }
phalcon: 缓存片段,文件缓存,memcache缓存的更多相关文章
- 记录一次读取memcache缓存的优化
我们是用mvc做web,大部分数据都用memcache做了缓存 有2台memcache缓存服务器 数据并不大. 某页面响应较慢,大概在4s左右. 页面本身很简单只是显示一个表单. 但是layout相对 ...
- linux 中的页缓存和文件 IO
本文所述是针对 linux 引入了虚拟内存管理机制以后所涉及的知识点.linux 中页缓存的本质就是对于磁盘中的部分数据在内存中保留一定的副本,使得应用程序能够快速的读取到磁盘中相应的数据,并实现不同 ...
- windows下ThinkPHP3.2.3使用memcache缓存
准备 要使用memcache,首先要安装配置好memcache服务memcached: 下载http://downloads.northscale.com/memcached-win64-1.4.4- ...
- memcached基于socket访问memcache缓存服务器
memcached基于socket访问memcache缓存服务器 操作memcache常用三种方法: .memcache基于php_memcache.dll扩展(php扩展) .memcached基于 ...
- 01-08-05【Nhibernate (版本3.3.1.4000) 出入江湖】NHibernate二级缓存:第三方MemCache缓存
一.准备工作 [1]根据操作系统(位数)选择下载相应版本的MemCache, MemCache的下载和安装,参看: http://www.cnblogs.com/easy5weikai/p/37606 ...
- spring memcache 缓存
application-cache.xml的配置 在web.xml中引入了这个配置文件 <context-param> <param-name>contextConfigLoc ...
- memcache缓存安装配置
memcache是高性能,分布式的内存对象缓存系统,用于在动态应用中减少数据库负载,提升访问速度.目前用memcache解决互联网上的大用户读取是非常流行的一种用法. 下载安装 前提要先安装libev ...
- DedeCMS V5.7开启memcache缓存的方法配置说明
一.安装Memcache服务:1.1.linux下的Memcache安装:-------------------------1. 下载 memcache的linux版本,注意 memcached 用 ...
- Windows服务器安装Memcache缓存服务及PHP扩展
一.Windows服务器安装Memcache缓存服务,需要下载windows稳定版Memcache程序memcached.zip,下载后解压到自定义服务目录,如D:\phpStudy\tools\me ...
随机推荐
- 华东交通大学2016年ACM“双基”程序设计竞赛 1004
Problem Description LB是个十分喜欢钻研的人,对什么事都要搞明白.有一天他看到一个公式,((a-b)*c+d*e)/f=k.他想如果给定K的值,一共有多少种不同整数的组合(a,b, ...
- linux 强大的编辑器之vi
vi编辑器是一个处理ASCII数据的文本工具.大多数linux发行版都已经默认安装了vi编辑器.vi是visual interface的缩写vim是 visual interface improved ...
- sql重新排序
declare @i int select @i = 10 update dbo.T_StartEndCode set @i = @i+1,OrderNumber = @i
- 编译android源码官方教程(2)建立编译环境「linux & mac osx」
https://source.android.com/source/initializing.html Establishing a Build Environment IN THIS DOCUMEN ...
- MTK+Android编译
1. 修改recovery代码 比如mediatek\custom\itek82_wet_kk\recovery\inc\cust_keys.h ./mk r k ./mk recoveryimage ...
- 可是把ie67下面的bug改好了,其实很简单,ie67下面取出来的字符串是带有空格的,不知道为什么
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...
- [Unity2D]Tags和Layers
Tags和Layers分别表示是Unity引擎里面的标签和层,他们都是用来对GameObject进行标识的属性,Tags常用于单个GameObject,Layers常用于一组的GameObject.添 ...
- Cheatsheet: 2013 08.20 ~ 08.31
.NET Protobuf-net: the unofficial manual 5 Common C# Misconceptions What is new in the Mono project ...
- Set Font Properties On Mouse Hover Of Push Button And Text Items At Run time In Oracle Forms
Change the font size and weight of text items and push buttons on mouse hover in Oracle Forms. An ...
- XML详解:第一部分
声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...