YII CACHE使用示例

从Boylee那抄过来的.链接中有boylee的博客地址. 我没有使用code插件,所以效果没有boy那的好,只是为了记录一下.如果需要复制代码之类的,请猛点此处

{Normal Cache}
01 //data cache
02 public function actionTestCache()
03 {
04 // print_r(Yii::app()->cache); //check the value
05 $cache = Yii::app()->cache;
06 $time = $cache->get('BoyLee001'); //get cache
07 if (false === $time){ //if cache is gone.
08 $cache->set('BoyLee001',time(),30); //set cache
09 // $cache['BoyLee001'] = $time(); //this is not right.
10 $time = $cache->get('BoyLee001');
11 }
12 echo $time;
13 }

{Fregment Cache}


01 //fregment cache
02 public function actionFregmentCache()
03 {
04 if ($this->beginCache('BoyLee002',
05 array('duration'=>60,
06 'dependency'=>array(
07 'class'=>'system.caching.dependencies.CDbCacheDependency',//you must have db set here
08 'sql'=>'SELECT COUNT(*) FROM `user`',//you must have db set here
09 ),
10 'varyByParam'=>array('id'),//cache by $_GET['id']
11 ))){
12 echo 'BoyLee'.time();
13 echo @$_GET['id'];
14 echo ' <hr /> ';
15 $this->endCache();
16 }
17 }

{PageCache}

{controller}
01 public function filters()
02 {
03 return array(
04 array('COutputCache + PageCache', 'duration'=>30,'varyByParam'=>array('id')),
05 );
06 }
07 public function actionPageCache()
08 {
09 $this->render('pageCache');
10 }

{view pageCache.php}
1 echo time();
2 echo ' <hr /> ';
3 echo @$_GET['id'];

{Boy Say}

It’s easy to use when you follow my code, just to be a bit change. I will update a post late for detail.
金融风控实战:用Python从零搭建贷款违约预测模型(附完整数据集) 本文详细介绍了如何使用Python从零构建金融风控中的贷款违约预测模型,涵盖数据清洗、特征工程、模型构建与评估等全流程。通过实战案例展示逻辑回归、XGBoost和LightGBM三大算法的对比,特别强调AUC-ROC指标在金融风控中的重要性,并附完整数据集和代码实现。 阅读详情

相关推荐

南京邮电大学电工电子基础B实验六(组合逻辑电路)

南京邮电大学电工电子基础B实验五(组合逻辑电路);电工电子;南京邮电大学;计算机学院;实验报告;电路图;

亦是远方的小地方 1万+

yii中缓存(cache)详解

缓存是用于提升网站性能的一种即简单又有效的途径。通过存储相对静态的数据至缓存以备所需,我们可以省去生成 这些数据的时间。 在 Yii 中使用缓存主要包括配置和访问缓存组件 。 内部方法 一、缓存配置: 1、单一缓存组件配置: Yii缓存可以在不同的级别使用。在最低级别,可用来缓存单个数据(数据缓存)。往上一级,我们缓存一个由视图脚本生成的页面片断(片段缓存)。在最高级别,可

大爱无疆的博客 4093

双向晶闸管交流调压基础知识及Multisim电路仿真

本文介绍了双向晶闸管交流调压电路的工作原理及应用。该电路由双向晶闸管、RC移相电路和双向触发二极管组成,通过调节电位器改变触发角实现电压调节。当电位器阻值减小时,触发角减小,输出电压升高;阻值增大时,触发角增大,输出电压降低。Multisim仿真展示了不同电位器档位下的波形特征:0%档位时全导通,50%档位时半导通,100%档位时基本关断。该电路结构简单、调节平滑,广泛应用于调光、调速等场合,但会产生谐波干扰。

XU157303764的博客 843

【Yii2】使用Cache缓存提高性能

Yii2 使用 Cache 缓存可以提高应用程序的性能,减轻服务器负担。Yii2 提供了多种缓存方法,如 MemCache、APC、Redis 等。这里以 Redis为例,介绍如何在 Yii2 中使用缓存。

q8688的博客 1635

Eclipse 数据空间组件(EDC)项目介绍

在当今数字经济的背景下,数据成为了新的“石油”。但与石油不同的是,数据可以无限共享且再生。然而,如何在保持数据主权的前提下实现高效、安全的数据共享,成为了企业和组织面临的主要挑战。这时,**Eclipse 数据空间组件(Eclipse Dataspace Components, EDC)**应运而生,它为企业在多方参与的数据交换中提供了一个标准化、可扩展的解决方案。数据空间不仅是一个多组织间的数据共享协议,还是一套支撑这些协议运行的技术基础设施。

m0_74331272的博客 4601

别再手动拷贝文件了!用Keil MDK的Pack Installer一键搞定STM32上的RT-Thread Nano移植

本文详细介绍了如何使用Keil MDK的Pack Installer一键快速移植RT-Thread Nano到STM32项目,告别繁琐的手动拷贝和配置过程。通过自动化版本管理和依赖处理,移植时间从47分钟缩短至3分钟,大幅提升开发效率。文章还提供了实战步骤、高级配置技巧和常见问题解决方案,帮助开发者轻松实现RTOS集成。

weixin_29194817的博客 364

Yii::$app->cache,可以同时配置多个缓存方式吗?底层原理是什么?

当获取或存储缓存数据时,Yii 将按照栈的顺序依次查找缓存数据,直到找到可用的缓存项或栈中没有可用的驱动。这样的栈式结构允许您在不同级别上配置不同的缓存方式,从而实现更灵活的缓存策略。从缓存中获取数据时,Yii 将按照缓存存储驱动栈的顺序依次查询每个驱动,直到找到对应的缓存项(如果存在)。将数据存储到缓存中时,Yii 将按照缓存存储驱动栈的顺序依次存储数据。首先,数据将被存储在栈顶的缓存驱动中,然后依次向下传递,存储到其他驱动。属性,表示缓存组件所使用的类,以及其他选项,如缓存存储驱动的配置。

长风破浪会有时的博客 384

ADF4002分频器避坑指南:常见配置错误及解决方案

本文深入解析了ADF4002分频器在实战应用中的常见陷阱与解决方案。内容涵盖寄存器配置逻辑、硬件PCB布局要点、软件驱动时序细节及系统化调试方法,重点阐述了如何避免因配置错误导致芯片无法正常工作的问题,帮助工程师高效完成高精度频率合成系统设计。

weixin_29192141的博客 96

yii cache 缓存命令

用命令从控制台刷新缓存 yii cache 显示可用缓存组件 yii cache/flush cache1 cache2 cache3 刷新缓存组件:cache1,cache2 和 cache3 yii cache/flush-all 刷新所有缓存组件

青崖梦 356

《Python等级认证CCF-GESP真题解析》专栏总目录

❤️ 专栏名称:《🌸 专栏介绍:中国计算机学会GESP《CCF编程能力等级谁》Python编程(1~8级)历届真题解析。🚀 订阅专栏:订阅后可阅读专栏内所有真题解析,真题持续更新中,限时9.9元,欢迎订阅!

人生就是一个不断学习的过程 1881

[STM32F103C8T6]W5500+Modbus TCP(HAL库)

本章节是博主学习Modbus TCP所写的一篇文章Modbus TCP是Modbus的一个分支,主要用到网口通信的,在工业上也用的很频繁,我们公司最近的项目就是用的W5500+modbus TCP来和PC端的上位机通信和交互的。虽然这个项目不是我在写代码,但是我都学了Modbus RTU了,那我也抽空学习一下Modbus TCP吧。本次的Modbus TCP不是博主写的,是一个大佬开源的一个W5500写的一个Mobus TCP代码,我在这个基础上自己写了主机读从机多个数据,和主机写从机寄存器的函数。

sinat_58149788的博客 4086

php yii cache/flush-all` 包含哪些部分?

【代码】php yii cache/flush-all` 包含哪些部分?

长风破浪会有时的博客 1007

第03章 Hermes Agent 核心原理

环境跑通之后,读者会很自然地想问:Hermes 的内部到底是怎么转起来的?为什么它能做到"越用越聪明"?长对话不会忘记上下文吗?这一章用尽量短的篇幅把核心原理讲清楚。理解原理不是为了纸上谈兵,而是为了在第7章实战时能判断"为什么 Hermes 这么响应"以及"我应该把哪类任务交给它"。

亢少军的博客 143

Yii2之cache的使用

第一步:配置cache 在config的components中添加 'cache' => [     'class' => 'yii\caching\FileCache', ] 第二步:设置cache Yii::$app->cache->set($key, $value, $expires_in); $key为cache的键,使用时根据$key值来获取相应的$value,需要注意的是

zlh13854157321的博客 1965

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

YII 缓存cache

ds.php.net/pierre/ 第二步:让php.ini支持apc扩展模块。 将php_apc.dll放入你的ext目录,然后打开php.ini 加入: extension=php_apc.dll apc.rfc1867 = on apc.max_file_size = 100M upload_max_filesize = 100M post_max_size = 100M apc.slam_defense = 0 apc.write_lock = 1 在配置文件中配置缓存,可以

hudeyong926的专栏 343

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

yii cache 缓存

yii cache 缓存   (2012-03-14 11:40:15) 转载▼ 标签:  杂谈 分类: yii 1.数据缓存 常见的缓存操作方法get,set,add,delete,flush默认的缓存文件保存到protected/runtime/目录。 ApcCache扩展配置 第一步:下载php_apc.dll 在h

可克技术 4436

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

yii2缓存Cache

<?php namespace frontend\controllers; use Yii; use frontend\models\LoginForm; class IndexController extends \yii\web\Controller { public function actionSite() { //设置缓存 /*Yii::$app->cache->set("name",666); //获取缓存 echo Yii::$app->cache

qq_37805832的博客 954

YII cache

1.数据缓存 常见的缓存操作方法get,set,add,delete,flush默认的缓存文件保存到protected/runtime/目录。 ApcCache扩展配置 第一步:下载php_apc.dll 在http://downloads.php.net/pierre/ 第二步:让php.ini支持apc扩展模块。 将php_apc.dll放入你的ex...

weixin_33937778的博客 88

Yii Cache 缓存的使用

我的缓存组件配置在config\main.php文件,配置如下: 'components' => [ 'cache' => [ 'class' => 'yii\caching\FileCache', 'cachePath' => '@runtime/cache2', ], ], 所谓的文件缓存,...

weixin_30263073的博客 114

Yii设置Cache缓存的方法

先在配置文件components数组中加上: 'cache'=&gt;array( 'class'=&gt;'CFileCache'), 设置Cache: Yii::app()-&gt;cache-&gt;set('testcache', array(1,3,4,6));//默认有效期为一年 Yii::app()-&gt;cache-&gt;set('testcache', ar...

weixin_33882452的博客 442

推荐文章:Redis Cache, Session 和 ActiveRecord for Yii 2 — 框架的高效扩展

推荐文章:Redis Cache, Session 和 ActiveRecord for Yii 2 — 框架的高效扩展 1、项目介绍 这款开源扩展专为 Yii Framework 2.0 设计,提供了强大的键值存储系统——Redis 的支持。它包括了一个 Cache 存储处理程序和 Session 存储处理器,并实现了 ActiveRecord 模式,使得你可以直接在 Redis 中存储 Act...

gitblog_00005的博客 471

Yii缓存机制yii\caching\Cache

前面讲到的缓存都是服务端缓存,在Yii中还可以使用客户端缓存去节省相同页面内容的生成和传输时间,即HTTP缓存,HTTP缓存使用到了yii\filters\HttpCache类,这个类也是一个过滤器,所以你要使用HTTP缓存,及在控制器的behaviors方法中引入yii\filters\HttpCache类,。片段缓存指的是缓存页面内容中的某个片段,如:在html中,你想要将一段html片段缓存起来,避免每次请求都重新生成此段html片段,这时候就可以使用片段缓存。

huaweichenai的博客 403

Yii源码分析之Cache

Cache是​​支持不同缓存存储实现的缓存类的基类。 数据项可以通过调用set()存储在缓存中,并通过get()稍后(在相同或不同的请求中)检索回来。在这两个操作中,都需要一个标识数据项的密钥。调用set()时也可以指定到期时间和/或依赖项。如果数据项到期或者在调用get()时依赖关系发生更改,则缓存将不返回任何数据。 缓存的典型使用模式如下: $key = 'demo'; $data = $...

lc的大脑备份 414

Yii2-Redis使用小记 - Cache(转)

前些天简单学习了下 Redis,现在准备在项目上使用它了。我们目前用的是 Yii2 框架,在官网搜索了下 Redis,就发现了yii2-redis这扩展。 安装后使用超简单,打开common/config/main.php文件,修改如下。 文本 'cache' => [ // 'class' => 'yii\caching\FileCache', ...

weixin_34327223的博客 120

PHP深入浅出学Yii2缓存Cache组件源码级详解(收藏不亏)

目录什么是缓存组件Cache定义缓存组件页面缓存PageCache配置页面缓存页面缓存PageCache是缓存组件Cache的一种应用自定义页面缓存过滤器页面缓存key的计算主动清理过期缓存优化缓存配置总结 什么是缓存组件Cache 缓存是提升 Web 应用性能简便有效的方式。 通过将相对静态的数据存储到缓存并在收到请求时取回缓存, 应用程序便节省了每次重新生成这些数据所需的时间。 定义缓存组件 Yii2的缓存是通过组件Component实现的,在项目的配置文件中,配置components->cac

Code Metaverse 1207
上一篇: Yii CDBHttpSession数据库存储session性能优化实战
下一篇: Yii CDBHttpSession数据库存储session性能优化实战
stevecj
博客等级 码龄25年 0粉丝 37原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值