


Yii database cache instance analysis, yii database instance analysis_PHP tutorial
Jul 12, 2016 am 08:55 AMYii database cache instance analysis, yii database instance analysis
The examples in this article describe the usage of Yii database cache. Share it with everyone for your reference, the details are as follows:
yii Operation database cache:
1. Add
to the main.php file'dbcache'=>array( 'class'=>'system.caching.CDbCache', //數(shù)據(jù)庫緩存,注意你自己的路徑問題 ),
2. Set up database cache
Yii::app()->cache->set($key,$value,$outtime); //$key 唯一主鍵,$value 對應(yīng)主鍵的值(可以是數(shù)組), $outtime 過期時(shí)間。
3. Get cache
Yii::app()->cache->get($key); //設(shè)置數(shù)據(jù)庫緩存時(shí)的主鍵key
4. Delete cache
Yii::app()->cache->delete($key);//同上
5. Clear cache files
Yii::app()->cache->fulsh(); //將刪除服務(wù)器上面的所有文件緩存,即cache文件夾里面的所有緩存文件
Application examples: (Many videos are not given in the list page. If cached, the list page needs to have page information. It is a little more complicated. Here is a database cache example of the list page)
The current url address: http://www.aaaa.com/news/list/gid/2/nid/3/page/1.html
First determine whether the cache exists:
if(isset($_GET['gid'])){ $gid = intval($_GET['gid']); }else{ $gid = 1; } ..........
I have omitted other judgment conditions here. Currently, the only information that needs to be judged is $gid, $nid, $pages (note that the current variable does not use $page but $pages, because if $page is used, it will An error occurred, conflicting with $page in paging)
$newsListCache = Yii::app()->cache->get("newsList$gid$nid$pages"); //可以保證其唯一性即可 if(!empty($newsListCache))//判定如果有這個(gè)文件則走這個(gè)文件 下面return 了所以后面的數(shù)據(jù)就不會(huì)再走了 return $newsListCache; 。。。。。//這里就是你的其他代碼數(shù)據(jù),不用管它 Yii::app()->cache->set("newsList$gid$nid$pages",$newsList,3600);//這里的第一個(gè)參數(shù)需要和上面的對應(yīng),第二個(gè)參數(shù)就是你的數(shù)據(jù) , 第三個(gè)參數(shù)就是過期時(shí)間。
Readers who are interested in more Yii-related content can check out the special topics on this site: "Introduction to Yii Framework and Summary of Common Techniques", "Summary of Excellent PHP Development Framework", "Basic Tutorial for Getting Started with Smarty Templates", "php Date and Time" Usage Summary", "php object-oriented programming introductory tutorial", "php string (string) usage summary", "php mysql database operation introductory tutorial" and "php common database operation skills summary"
I hope this article will be helpful to everyone’s PHP program design based on the Yii framework.
Articles you may be interested in:
- YII Framework filter usage analysis
- Introduction to some advanced usage of caching in PHP's Yii framework
- In-depth analysis of the caching function in PHP's Yii framework
- Advanced use of View in PHP's Yii framework
- Study tutorial on Model model in PHP's Yii framework
- Detailed explanation Controller controller in PHP's Yii framework
- Yii's method of turning on fragment caching
- Detailed explanation of attribute injection and method injection of component behavior in PHP's Yii framework
- Detailed explanation in PHP Methods of using Behaviors in Yii Framework
- YII Framework learning request and response usage (based on CHttpRequest response)

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

The key to installing MySQL 8.0 is to follow the steps and pay attention to common problems. It is recommended to use the MSI installation package on Windows. The steps include downloading the installation package, running the installer, selecting the installation type, setting the root password, enabling service startup, and paying attention to port conflicts or manually configuring the ZIP version; Linux (such as Ubuntu) is installed through apt, and the steps are to update the source, installing the server, running security scripts, checking service status, and modifying the root authentication method; no matter which platform, you should modify the default password, create ordinary users, set up firewalls, adjust configuration files to optimize character sets and other parameters to ensure security and normal use.

The main difference between senior Yii developers and junior Yii developers is experience, depth of skills and way of thinking. 1. Senior developers pay attention to performance optimization and code reconstruction, and use Yii's cache mechanism to improve application performance. 2. They deeply understand Yii's underlying principles, participate in architectural design and technical decision-making, and use modular design to build flexible applications. 3. Senior developers pay attention to overall project planning and long-term development and play the role of mentor. Junior developers need to gradually improve through learning and practice, and eventually grow into senior developers.

The way to view all databases in MongoDB is to enter the command "showdbs". 1. This command only displays non-empty databases. 2. You can switch the database through the "use" command and insert data to make it display. 3. Pay attention to internal databases such as "local" and "config". 4. When using the driver, you need to use the "listDatabases()" method to obtain detailed information. 5. The "db.stats()" command can view detailed database statistics.

Common SQL statements include: 1. CREATETABLE creates tables, such as CREATETABLEemployees(idINTPRIMARYKEY, nameVARCHAR(100), salaryDECIMAL(10,2)); 2. CREATEINDEX creates indexes, such as CREATEINDEXidx_nameONemployees(name); 3. INSERTINTO inserts data, such as INSERTINTO employeees(id, name, salary)VALUES(1,'JohnDoe',75000.00); 4. SELECT check

To create new records in the database using Eloquent, there are four main methods: 1. Use the create method to quickly create records by passing in the attribute array, such as User::create(['name'=>'JohnDoe','email'=>'john@example.com']); 2. Use the save method to manually instantiate the model and assign values ??to save one by one, which is suitable for scenarios where conditional assignment or extra logic is required; 3. Use firstOrCreate to find or create records based on search conditions to avoid duplicate data; 4. Use updateOrCreate to find records and update, if not, create them, which is suitable for processing imported data, etc., which may be repetitive.

To install the Yii framework, you need to configure PHP and Composer according to different operating systems. The specific steps are as follows: 1. You need to manually download PHP and configure environment variables on Windows, then install Composer, use commands to create a project and run a built-in server; 2. It is recommended to use Homebrew to install PHP and Composer, then create a project and start a development server; 3. Linux (such as Ubuntu) install PHP, extensions and Composer through apt, then create a project and deploy a formal environment with Apache or Nginx. The main differences between different systems are in the environment construction stage. Once PHP and Composer are ready, the subsequent processes are consistent. Note

Yiidevelopersshouldadheretothesekeycodingstandards:1)FollowPSR-2forconsistentindentationandnamingconventions,2)UseYii-specificnamingconventionsformodels,controllers,andviews,3)EmployautomatedtoolslikePHP_CodeSnifferforconsistency,4)Keepmodelsleanusin

BLOBinMySQLisadatatypeusedforstoringbinarydatalikeimagesanddocuments.Touseiteffectively:1)ChoosetheappropriateBLOBtypebasedondatasize,2)ConsiderperformanceimpactsandpossiblyuseseparatetablesforBLOBs,3)Usestreamingfordataretrieval,4)Ensurerobustbackup
