- 浏览: 13793113 次
- 性别:
- 来自: 洛杉矶
-
文章分类
- 全部博客 (1994)
- Php / Pear / Mysql / Node.js (378)
- Javascript /Jquery / Bootstrap / Web (435)
- Phone / IOS / Objective-C / Swift (137)
- Ubuntu / Mac / Github / Aptana / Nginx / Shell / Linux (335)
- Perl / Koha / Ruby / Markdown (8)
- Java / Jsp (12)
- Python 2 / Wxpython (25)
- Codeigniter / CakePHP (32)
- Div / Css / XML / HTML5 (179)
- WP / Joomla! / Magento / Shopify / Drupal / Moodle / Zimbra (275)
- Apache / VPN / Software (31)
- AS3.0/2.0 / Flex / Flash (45)
- Smarty (6)
- SEO (24)
- Google / Facebook / Pinterest / SNS (80)
- Tools (22)
最新评论
-
1455975567:
xuezhongyu01 写道wocan23 写道我想问下那个 ...
Mysql: LBS实现查找附近的人 (两经纬度之间的距离) -
xuezhongyu01:
wocan23 写道我想问下那个111.1是怎么得来的我也看不 ...
Mysql: LBS实现查找附近的人 (两经纬度之间的距离) -
18335864773:
试试 pageoffice 在线打开 PDF 文件吧. pag ...
jquery在线预览PDF文件,打开PDF文件 -
青春依旧:
opacity: 0.5; 个人喜欢这种方式!关于其他css特 ...
css透明度的设置 (兼容所有浏览器) -
July01:
推荐用StratoIO打印控件,浏览器和系统的兼容性都很好,而 ...
搞定网页打印自动分页问题
codeigniter的功能纵然强大,也有不足之处。其cache模式在于针对不同的uri就会生成cache文件,如果URL中参数不同,则 cache文件就会不同,从而产生了漏洞。如果访问者构建自动生成URI,不断向服务器发起请求,就会瞬间产生大量的垃圾文件,导致系统文件臃肿。
参看CI中国论坛:脆弱的CI缓存系统,1天攻陷你的CI网站http://codeigniter.org.cn/forums/thread- 1690-1-1.html
因此如果要用到cache功能就必须找到第三方的开发库。Pear中,Cache_Lite属于较为轻量级的缓存系统,且功能强大,可以作为CI原 生cache的替代品,将其加入自定义的library文件即可完成。
步骤如下:
1. 下载Cache_Lite
http://download.pear.php.net/package/Cache_Lite-1.7.7.tgz
解压缩后,将Cache_Lite.php和Lite文件夹复制到 system/application/libraries中。并在Cache_Lite.php中加入:if (!defined(’BASEPATH’)) exit(’No direct script access allowed’);
2. 在要使用Cache_Lite的Controller中,加入:
$ops = array( ‘cacheDir’ => BASEPATH.’/cache/’, //cache文件存储位置 ‘lifeTime’ => 3600, //cache的有效期 ); // ; $this->load->library(”Cache_Lite”,$ops,”cc”); //cc为Cache_Lite的别名, 然后在要利用Cache的位置使用Cache_Lite自带的函数就可以拉。
如:读取缓存:$string = $this->cc->get($id);
生成缓存:$this->cc->save($outputString);
推荐一个更好的CI缓存类:MP_Cache
首先,在config.php中设置一下缓存目录,这个目录要存在且可写入
$config['mp_cache_dir'] = 'application/mp_cache/';
现在看看代码
/*加载library,可以放在构造函数中*/ $this->load->library('MP_Cache'); /*抓取名为listNews的缓存*/ $listNews = $this->mp_cache->get('listNews'); if($listNews===false){ //没有缓存数据,则查询数据库 $listNews = $this->News_model->getNewslist('guest')->result(); //创建缓存,命名为listNews。在mp_cache目录下就生成了listNews.cache文件,内容是序列化的数据 $this->mp_cache->write($listNews, 'listNews'); } $data['listNews']= $listNews; $this->layout->view('news', $data);
两个注意点:
1,缓存数据,必须是data,而不是resource id。如,在使用AR后用result(),result_array()等返回的数据
2,缓存名不要重复。可以使用子文件夹分隔。如,$listNews =
$this->mp_cache->get(‘news/listNews’);同样创建缓存数据片段
用$this->mp_cache->write($listNews,
‘news/listNews’);(php5下news文件夹会自动创建)
其他方法:
$this->mp_cache->delete($filename)
删除名为$filename的cache.
$this->mp_cache->delete_all($dirname)
删除 $dirname目录及其下所有缓存.如果$dirname没有设置,则删除所有缓存.
http://mpsimple.mijnpraktijk.com/mp_cache/user_guide.htm
MP_Cache was written as a more flexible caching solution than those offered by CodeIgniter. As such it offers you a way to cache anything from a single variable, to a SQL query or the fully generated page. MP_Cache saves these entries serialized to files and has functions to retrieve and delete these.
Additionally you can set expiration time and dependencies to force a main cache to refresh itself after one of its subcaches has been refreshed or deleted.
Installing MP_Cache
- Download the file here and unzip it to your application/libraries directory.
- Create a directory for you cache, for example application/mp_cache
- Add
a value 'mp_cache_dir' to an autoloaded config file, for instance application/config/config.php
and set it to the mp_cache directory relative to your index.php file.
For example: $config['mp_cache_dir'] = APPPATH.'mp_cache/'; - Optional: add a value 'mp_cache_default_expires' to the same autoloaded config file and set it to a default expiration time in seconds if you want it set by default. You can still make something never expire by setting it to 0.
- That's it, you can start using MP_Cache.
Initializing MP_Cache
Like most other classes in CodeIgniter, the MP_Cache class is initialized in your controller using the
$this->load->library function :
$this->load->library('MP_Cache');
Once the library is loaded it will be ready for use. The MP_Cache library object you will use to call all functions is: $this->mp_cache .
Basic caching without additional settings
To just cache something within your controller or model, the usage is like this:
$data = $this->mp_cache->get('example'); if ($data === false) { // example model-function that generates your $data variable $data = $this->Pages->read($page); $this->mp_cache->write($data, 'example'); }
The variable to be cached can be of any kind, though object-references will be lost when loaded from cache.
Alternative syntax for the example above
You can also use the cache in a more object oriented way. In this case you always call the set_name() method before any other because it will reset the object to its default state.
$data = $this->mp_cache->set_name('example')->get(); if ($data === false) { // example model-function that generates your $data variable $data = $this->Pages->read($page); $this->mp_cache->set_contents($data)->write(); }
Warning: You can't combine the syntaxes, using the parameterized versions of write() and get() will reset the mp_cache object to prevent contamination of your current cache operation from a previous one.
Using subdirectories
For PHP5 subdirectories with virtual unlimited depth are supported, PHP4 only supports 1 level. You can set subdirectories by simply adding them in the cache name. The first line of the alternative syntax example is below in the directory "directory " which in turn is in the directory "sub ".
$data = $this->mp_cache->set_name('sub/directory/example')->get();
Adding an expiration time
Expiration time is added when writing the cache. Exparation is set to NULL by default which means using the default expiration, you can set it to 0 for no experation (if the default is set to something larger than 0). If you want it to expire after a certain time you have to specify it in seconds after it was generated. To do so you have to change the write function like this when using the write() function with parameters:
// Cache it for 2 hours (7200 seconds = 60 seconds * 60 minutes * 2 hours) $this->mp_cache->write($data, 'example', 7200);
Or do it by using the set_expires() function:
$this->mp_cache->set_name('example')->set_contents($data)->set_expires(7200)->write();
Adding dependencies
You can add cache file on which the expiration of the current cache file is dependend. When one of those files has been deleted or refreshed after the current cache was made, the current cache will be deleted. So lets say we have a menu called mainmenu which we have cached in a subdirectory called menus . Using the parameterized write() function you can add the dependency like this (expiration set to none):
$this->mp_cache->write($data, 'example', null, array('menus/mainmenu'));
Or using the set_dependencies() function (which takes an array or a string):
$this->mp_cache->set_name('example')->set_contents($data)->set_dependencies('menus/mainmenu')->write();
Deleting individual caches
You can delete cache by using the delete() function:
$this->mp_cache->delete('example');
Or in the alternative way:
$this->mp_cache->set_name('example')->delete();
Deleting the entire cache or subdirectories of it
To delete the entire cache you can use the delete_all() function:
$this->mp_cache->delete_all();
Or you can delete a subdirectory of the main cache, like all the menus from the example for dependencies:
$this->mp_cache->delete_all('menus');
This will delete all the files in the subdirectory menus of the main cache. All the subdirectories of the menus directory and files within them will also be deleted.
Full functions overview
reset()
Resets the current state of the mp_cache object. It is called automatically from the set_name() function or when the write() & get() functions are used with parameters. This is done to prevent any previous usage of the mp_cache object from contaminating your current usage with settings you would expect to be the default ones.
$this->mp_cache->reset();
set_name() & get_name()
Sets or returns the full filename of the cache.
Warning:
the set_name() function automatically calls reset(), so always use it
as the first function when using the alternative syntax.
$this->mp_cache->set_name('example'); // after this is set the variable below will be set to the string 'example' $var = $this->mp_cache->get_name();
set_contents() & get_contents()
Sets or returns the contents you are caching or retrieving.
$this->mp_cache->set_contents(array(1,2,3,4,5)); // The function below will return the array set above $array = $this->mp_cache->get_contents();
set_dependencies(), add_dependencies() & get_dependencies()
Sets the dependencies, adds to the current dependencies or returns the set dependencies.
$this->mp_cache->set_dependencies('example'); // this sets the dependencies to the 'example' cache file $this->mp_cache->set_dependencies(array('cachefile1', 'cachefile2')); // this has overwritten the first statement and set the dependencies to 'cachefile1' & 'cachefile2' $this->mp_cache->add_dependencies('example') // this has added 'example' as a dependency in addition to 'cachefile1' & 'cachefile2'
All functions take both strings and arrays of strings.
set_expires() & get_expires()
Sets the expiration time and retrieves the time on which the cache will expire.
$this->mp_cache->set_expires(7200); // sets the expiration to a timestamp 2 hours from now $expires = $this->mp_cache->get_expires(); // $expires is set to the timestamp 2 hours from now as defined by set_expires()
get_created()
Returns the timestamp from the moment the retrieved cache was created, returns NULL when used while writing cache.
$created_on = $this->mp_cache->get_created();
- Cache_Lite-1.7.7.rar (29.3 KB)
- 下载次数: 11
- MP_Cache.zip (2.5 KB)
- 下载次数: 55
发表评论
-
CakePHP你必须知道的21条技巧
2012-10-19 06:25 1901原文链接:http://www.avatarfinancial ... -
cakephp 1.3 Views
2012-10-09 06:12 1460Section 1 Views 视图 一个vie ... -
cakephp 1.3 Models
2012-10-09 06:07 2514Section 1 What is a model? ... -
cakephp 1.3 Controller
2012-10-09 05:49 3347Controller 一个controller用于管理 ... -
cakephp 1.3 配置CakePHP
2012-10-09 05:31 4666Section 1 数据库配置 app/config/ ... -
CakePHP 2.x十分钟博客教程
2012-10-07 01:27 244461. CakePHP2十分钟博客教 ... -
Create an Admin panel with CodeIgniter
2010-05-23 02:15 4191Create an Admin panel with Code ... -
Codeigniter Grid 使用方法 (flexigrid)
2010-05-23 02:05 2839来源:http://codeigniter.com/forum ... -
CI集成 ckeditor 配置
2010-05-23 01:34 3767配置 ckeditor 1.上传 下载 ckedito ... -
codeigniter 辅助函数 - 敏感词过滤
2010-05-05 06:18 4594我们都知道有些敏感的词汇是不适合出现在互联网上的,特别是在有用 ... -
实现简单 codeigniter 缓存 (cache)
2010-04-30 23:47 5307代码 class Test extends Contr ... -
CKEditor Helper for CodeIgniter
2010-04-19 00:37 4004Using CKEditor as a plugin in y ... -
codeigniter 生成 excel
2010-04-19 00:33 3349Excel Plugin Th ... -
CakePHP 中文手册
2010-04-14 21:04 2361基本概念 Section1 简介 ... -
CodeIgniter 操作PDF ( Generating PDF files using CodeIgniter )
2010-01-03 04:03 3631PDF files rock! Some of the p ... -
CodeIgniter 合作 Authorize.net
2009-12-30 00:25 1636function payment(){ // 略... ... -
CodeIgniter 合作paypal
2009-12-30 00:15 2380<?php class Paypal extend ... -
CodeIgniter 操作 CSV
2009-12-29 07:17 4669A Comma separated values (CSV) ... -
codeigniter 操作 Rss
2009-12-29 07:12 2008I wrote a codeigniter library t ... -
codeigniter操作xml
2009-12-29 06:57 4014This Simplexml class provides a ...
相关推荐
通过使用PHP缓存机制,如Cache_Lite等,可以将常用的数据存储在内存中,减少对数据库的依赖。这样不仅能够提高网站的速度,还能减轻服务器的压力。Ben推荐了几种常用的PHP缓存方法,比如Memcached和APC等,它们在...
KUKA机器人相关资料
内容概要:本文详细介绍了利用Matlab实现模拟退火算法来优化旅行商问题(TSP)。首先阐述了TSP的基本概念及其在路径规划、物流配送等领域的重要性和挑战。接着深入讲解了模拟退火算法的工作原理,包括高温状态下随机探索、逐步降温过程中选择较优解或以一定概率接受较差解的过程。随后展示了具体的Matlab代码实现步骤,涵盖城市坐标的定义、路径长度的计算方法、模拟退火主循环的设计等方面。并通过多个实例演示了不同参数配置下的优化效果,强调了参数调优的重要性。最后讨论了该算法的实际应用场景,如物流配送路线优化,并提供了实用技巧和注意事项。 适合人群:对路径规划、物流配送优化感兴趣的科研人员、工程师及高校学生。 使用场景及目标:适用于需要解决复杂路径规划问题的场合,特别是涉及多个节点间最优路径选择的情况。通过本算法可以有效地减少路径长度,提高配送效率,降低成本。 其他说明:文中不仅给出了完整的Matlab代码,还包括了一些优化建议和技术细节,帮助读者更好地理解和应用这一算法。此外,还提到了一些常见的陷阱和解决方案,有助于初学者避开常见错误。
内容概要:本文详细介绍了如何利用Simulink进行自动代码生成,在STM32平台上实现带57次谐波抑制功能的霍尔场定向控制(FOC)。首先,文章讲解了所需的软件环境准备,包括MATLAB/Simulink及其硬件支持包的安装。接着,阐述了构建永磁同步电机(PMSM)霍尔FOC控制模型的具体步骤,涵盖电机模型、坐标变换模块(如Clark和Park变换)、PI调节器、SVPWM模块以及用于抑制特定谐波的陷波器的设计。随后,描述了硬件目标配置、代码生成过程中的注意事项,以及生成后的C代码结构。此外,还讨论了霍尔传感器的位置估算、谐波补偿器的实现细节、ADC配置技巧、PWM死区时间和换相逻辑的优化。最后,分享了一些实用的工程集成经验,并推荐了几篇有助于深入了解相关技术和优化控制效果的研究论文。 适合人群:从事电机控制系统开发的技术人员,尤其是那些希望掌握基于Simulink的自动代码生成技术,以提高开发效率和控制精度的专业人士。 使用场景及目标:适用于需要精确控制永磁同步电机的应用场合,特别是在面对高次谐波干扰导致的电流波形失真问题时。通过采用文中提供的解决方案,可以显著改善系统的稳定性和性能,降低噪声水平,提升用户体验。 其他说明:文中不仅提供了详细的理论解释和技术指导,还包括了许多实践经验教训,如霍尔传感器处理、谐波抑制策略的选择、代码生成配置等方面的实际案例。这对于初学者来说是非常宝贵的参考资料。
内容概要:本文详细介绍了基于西门子S7-200 PLC和组态王的机械手搬运控制系统的实现方案。首先,文章展示了梯形图程序的关键逻辑,如急停连锁保护、水平移动互锁以及定时器的应用。接着,详细解释了IO分配的具体配置,包括数字输入、数字输出和模拟量接口的功能划分。此外,还讨论了接线图的设计注意事项,强调了电磁阀供电和继电器隔离的重要性。组态王的画面设计部分涵盖了三层画面结构(总览页、参数页、调试页)及其动画脚本的编写。最后,分享了调试过程中遇到的问题及解决方案,如传感器抖动、输出互锁设计等。 适合人群:从事自动化控制领域的工程师和技术人员,尤其是对PLC编程和组态软件有一定基础的读者。 使用场景及目标:适用于自动化生产线中机械手搬运控制系统的开发与调试。目标是帮助读者掌握从硬件接线到软件逻辑的完整实现过程,提高系统的稳定性和可靠性。 其他说明:文中提供了大量实践经验,包括常见的错误和解决方案,有助于读者在实际工作中少走弯路。
内容概要:本文详细介绍了基于西门子1200PLC的污水处理项目,涵盖了PLC程序结构、通信配置、HMI设计以及CAD原理图等多个方面。PLC程序采用梯形图和SCL语言相结合的方式,实现了复杂的控制逻辑,如水位控制、曝气量模糊控制等。通讯配置采用了Modbus TCP和Profinet双协议,确保了设备间高效稳定的通信。HMI设计则注重用户体验,提供了详细的报警记录和趋势图展示。此外,CAD图纸详尽标注了设备位号,便于后期维护。操作说明书中包含了应急操作流程和定期维护建议,确保系统的长期稳定运行。 适合人群:从事工业自动化领域的工程师和技术人员,尤其是对PLC编程、HMI设计和通信配置感兴趣的从业者。 使用场景及目标:适用于污水处理厂及其他类似工业控制系统的设计、实施和维护。目标是帮助工程师掌握完整的项目开发流程,提高系统的可靠性和效率。 其他说明:文中提供的具体代码片段和设计思路对于理解和解决实际问题非常有价值,建议读者结合实际项目进行深入学习和实践。
内容概要:本文详细介绍了基于5电平三相模块化多电平变流器(MMC)的虚拟同步发电机(VSG)控制系统的构建与仿真。首先,文章描述了MMC的基本结构和参数设置,包括子模块电容电压均衡策略和载波移相策略。接着,深入探讨了VSG控制算法的设计,特别是有功-频率和无功-电压下垂控制的具体实现方法。文中还展示了通过MATLAB-Simulink进行仿真的具体步骤,包括设置理想的直流电源和可编程三相源来模拟电网扰动。仿真结果显示,VSG控制系统能够在面对频率和电压扰动时迅速恢复稳定,表现出良好的调频调压性能。 适合人群:从事电力电子、电力系统自动化及相关领域的研究人员和技术人员。 使用场景及目标:适用于研究和开发新型电力电子设备,特别是在新能源接入电网时提高系统的稳定性。目标是通过仿真验证VSG控制的有效性,为实际应用提供理论支持和技术指导。 其他说明:文章提供了详细的代码片段和仿真配置,帮助读者更好地理解和重现实验结果。此外,还提到了一些常见的调试技巧和注意事项,如选择合适的仿真步长和参数配对调整。
内容概要:本文详细介绍了在一个复杂的工业自动化项目中,如何利用西门子S7-1200 PLC为核心,结合基恩士视觉相机、ABB机器人以及G120变频器等多种设备,构建了一个高效的立体库码垛系统。文中不仅探讨了不同设备之间的通信协议(如Modbus TCP和Profinet),还展示了SCL和梯形图混合编程的具体应用场景和技术细节。例如,通过SCL进行视觉坐标解析、机器人通信心跳维护等功能的实现,而梯形图则用于处理简单的状态切换和安全回路。此外,作者分享了许多实际调试过程中遇到的问题及其解决方案,强调了良好的注释习惯对于提高代码可维护性的关键作用。 适用人群:从事工业自动化领域的工程师和技术人员,尤其是对PLC编程、机器人控制及多种通信协议感兴趣的从业者。 使用场景及目标:适用于需要整合多种工业设备并确保它们能够稳定协作的工作环境。主要目标是在保证系统高精度的同时降低故障率,从而提升生产效率。 其他说明:文中提到的一些具体技术和方法可以作为类似项目的参考指南,帮助开发者更好地理解和应对复杂的工业控制系统挑战。
KUKA机器人相关资料
java脱敏工具类
内容概要:本文详细介绍了基于自抗扰控制(ADRC)的表贴式永磁同步电机(SPMSM)双环控制系统的建模与实现方法。该系统采用速度环一阶ADRC控制和电流环PI控制相结合的方式,旨在提高电机在复杂工况下的稳定性和响应速度。文章首先解释了选择ADRC的原因及其优势,接着展示了ADRC和PI控制器的具体实现代码,并讨论了在Matlab/Simulink环境中搭建模型的方法和注意事项。通过对不同工况下的仿真测试,验证了该控制策略的有效性,特别是在负载突变情况下的优越表现。 适合人群:从事电机控制、自动化控制及相关领域的研究人员和技术人员,尤其是对自抗扰控制感兴趣的工程师。 使用场景及目标:适用于需要高精度、高响应速度的工业伺服系统和其他高性能电机应用场景。目标是提升电机在复杂环境下的稳定性和抗扰能力,减少转速波动和恢复时间。 其他说明:文中提供了详细的代码示例和调试技巧,帮助读者更好地理解和实施该控制策略。同时,强调了在实际应用中需要注意的问题,如参数调整、输出限幅等。
java设计模式之责任链的使用demo
内容概要:本文详细介绍了两相交错并联Buck/Boost变换器的硬件结构和三种控制方式(开环、电压单环、双环)的实现方法及仿真结果。文中首先描述了该变换器的硬件结构特点,即四个MOS管组成的H桥结构,两相电感交错180度工作,从而有效减少电流纹波。接着,针对每种控制方式,具体讲解了其配置步骤、关键参数设置以及仿真过程中需要注意的问题。例如,在开环模式下,通过固定PWM占空比来观察原始波形;电压单环则引入PI控制器进行电压反馈调节;双环控制进一步增加了电流内环,实现了更为精确的电流控制。此外,文章还探讨了单向结构的特点,并提供了仿真技巧和避坑指南。 适合人群:从事电力电子研究的技术人员、高校相关专业师生。 使用场景及目标:适用于希望深入了解两相交错并联Buck/Boost变换器的工作原理和技术细节的研究者,旨在帮助他们掌握不同控制方式的设计思路和仿真方法。 其他说明:文中不仅提供了详细的理论解释,还有丰富的实例代码片段,便于读者理解和实践。同时,作者分享了许多宝贵的实践经验,有助于避免常见的仿真错误。
第二场c++A组
数控磨床编程.ppt
内容概要:本文详细介绍了利用COMSOL软件进行N2和CO2混合气体在热-流-固三场耦合作用下增强煤层气抽采的数值模拟。首先,通过设定煤岩材料参数,如热导率、杨氏模量等,构建了煤岩物理模型。接着,引入达西定律和Maxwell-Stefan扩散方程,建立了混合气体运移方程,考虑了气体膨胀系数和吸附特性。在应力场求解方面,采用自适应步长和阻尼系数调整,确保模型稳定。同时,探讨了温度场与气体运移的耦合机制,特别是在低温条件下CO2注入对煤体裂隙扩展的影响。最后,通过粒子追踪和流线图展示了气体运移路径和抽采效率的变化。 适合人群:从事煤层气开采、数值模拟以及相关领域的科研人员和技术工程师。 使用场景及目标:适用于需要优化煤层气抽采工艺的研究机构和企业,旨在通过数值模拟提高抽采效率并减少环境影响。 其他说明:文中提供了详细的MATLAB和COMSOL代码片段,帮助读者理解和复现模型。此外,强调了模型参数选择和求解器配置的重要性,分享了作者的实际经验和常见问题解决方法。
基于Bode的引线补偿器设计 计算给定G、相位裕度、交叉频率和安全裕度要求的引线补偿器。 计算给定电厂G、PM和Wc要求的铅补偿器,并运行ControlSystemDesigner进行验证。
KUKA机器人相关文档