yii2缓存的介绍和使用,yii2缓存介绍使用
yii2缓存的介绍和使用,yii2缓存介绍使用
作者:白狼 出处:http://www.manks.top/yii2_cache.html 本文版权归作者,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
一个好的框架是肯定离不开缓存的使用,相反,一个没有缓存的框架也肯定不是一个好框架,好像是一个意思,不管了,我们先来看看yii2中是如何使用缓存的吧。
又是到我们第一步操作的时候了,我们先来配置组件。
方便起见,我们的缓存组件配置在common\config\main.php文件,先来简单配置下文件缓存
'components' => [ <br /> 'cache' => [ <br /> 'class' => 'yii\caching\FileCache', <br /> 'cachePath' => '@runtime/cache2', <br /> ], <br />],
<span>所谓的文件缓存,其实就是把我们要缓存的数据存放到文件内,那数据又缓存到哪里了呢?</span>
//默认的缓存路径是@app\runtime\cache目录下,如果你想要修改缓存路径,可以像上面配置一样,配置下cachePath即可
我们直接来操作看看
<span>$cache</span> = Yii::<span>$app</span>-><span>cache; </span><span>$data</span> = <span>$cache</span>->get('cache_data_key'<span>); </span><span>if</span> (<span>$data</span> === <span>false</span><span>) { </span><span>//</span><span>这里我们可以操作数据库获取数据,然后通过$cache->set方法进行缓存 </span> <span>$cacheData</span> = ...... <span>//</span><span>set方法的第一个参数是我们的数据对应的key值,方便我们获取到 //第二个参数即是我们要缓存的数据 //第三个参数是缓存时间,如果是0,意味着永久缓存。默认是0 </span> <span>$cache</span>->set('cache_data_key', <span>$cacheData</span>, 60*60<span>); } </span><span>var_dump</span>(<span>$data</span>);
继续阅读

Hot AI Tools

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

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

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

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

CrystalDiskMark is a small HDD benchmark tool for hard drives that quickly measures sequential and random read/write speeds. Next, let the editor introduce CrystalDiskMark to you and how to use crystaldiskmark~ 1. Introduction to CrystalDiskMark CrystalDiskMark is a widely used disk performance testing tool used to evaluate the read and write speed and performance of mechanical hard drives and solid-state drives (SSD). Random I/O performance. It is a free Windows application and provides a user-friendly interface and various test modes to evaluate different aspects of hard drive performance and is widely used in hardware reviews

Cloud storage has become an indispensable part of our daily life and work nowadays. As one of the leading cloud storage services in China, Baidu Netdisk has won the favor of a large number of users with its powerful storage functions, efficient transmission speed and convenient operation experience. And whether you want to back up important files, share information, watch videos online, or listen to music, Baidu Cloud Disk can meet your needs. However, many users may not understand the specific use method of Baidu Netdisk app, so this tutorial will introduce in detail how to use Baidu Netdisk app. Users who are still confused can follow this article to learn more. ! How to use Baidu Cloud Network Disk: 1. Installation First, when downloading and installing Baidu Cloud software, please select the custom installation option.

NetEase Mailbox, as an email address widely used by Chinese netizens, has always won the trust of users with its stable and efficient services. NetEase Mailbox Master is an email software specially created for mobile phone users. It greatly simplifies the process of sending and receiving emails and makes our email processing more convenient. So how to use NetEase Mailbox Master, and what specific functions it has. Below, the editor of this site will give you a detailed introduction, hoping to help you! First, you can search and download the NetEase Mailbox Master app in the mobile app store. Search for "NetEase Mailbox Master" in App Store or Baidu Mobile Assistant, and then follow the prompts to install it. After the download and installation is completed, we open the NetEase email account and log in. The login interface is as shown below

MetaMask (also called Little Fox Wallet in Chinese) is a free and well-received encryption wallet software. Currently, BTCC supports binding to the MetaMask wallet. After binding, you can use the MetaMask wallet to quickly log in, store value, buy coins, etc., and you can also get 20 USDT trial bonus for the first time binding. In the BTCCMetaMask wallet tutorial, we will introduce in detail how to register and use MetaMask, and how to bind and use the Little Fox wallet in BTCC. What is MetaMask wallet? With over 30 million users, MetaMask Little Fox Wallet is one of the most popular cryptocurrency wallets today. It is free to use and can be installed on the network as an extension

Xiaomi car software provides remote car control functions, allowing users to remotely control the vehicle through mobile phones or computers, such as opening and closing the vehicle's doors and windows, starting the engine, controlling the vehicle's air conditioner and audio, etc. The following is the use and content of this software, let's learn about it together . Comprehensive list of Xiaomi Auto app functions and usage methods 1. The Xiaomi Auto app was launched on the Apple AppStore on March 25, and can now be downloaded from the app store on Android phones; Car purchase: Learn about the core highlights and technical parameters of Xiaomi Auto, and make an appointment for a test drive. Configure and order your Xiaomi car, and support online processing of car pickup to-do items. 3. Community: Understand Xiaomi Auto brand information, exchange car experience, and share wonderful car life; 4. Car control: The mobile phone is the remote control, remote control, real-time security, easy

How to use Dewu installment purchase? You can use the installment payment service to purchase your favorite goods in Dewu APP. Most people don’t know how to use Dewu installment purchase. Next is the Dewu installment purchase brought by the editor to users. Graphic tutorial on how to use it. Interested users can come and take a look! Dewu usage tutorial How to use Dewu installment purchase 1. First open Dewu APP and enter the main page, select your favorite product and enter the purchase page; 2. Then on the product purchase page in the picture below, click [Buy Now] in the lower right corner; 3 , then select the appropriate code number and click the price on the left; 4. Then on the order confirmation page, select [Submit Order] in the lower right corner; 5. Finally, on the payment page, check the button behind [Huabei Installment]. Just select the installment type and you’re done

In Hua Yishan Heart Moon, Lu Shu is an SSR celebrity. He is positioned as a single-target backline player and has a very impressive critical hit rate. Many players don’t know much about Lu Shu. Here’s what I’ve brought you. Come and take a look at the introduction to the skills and attributes of Hua Yishan Heart of the Moon Lu Shu. Celebrity Attributes Celebrity Skills 1. Lu Ming Shuzhong Skill Description: Lu Shu was born in Qiongqihui in Shuzhong. He has practiced martial arts since he was a child and has outstanding martial arts skills. Causes basic attack damage equal to 100% of the enemy's back row attack power, and reduces the target's rage by 10 points. Skill attributes: Level 2: Basic attack damage increased to 105%. Level 2: Basic attack damage is increased to 110%, and the target's rage is reduced by 15 points. Level 2: Basic attack damage increased to 115%. Level 2: Basic attack damage is increased to 120%, and the target's rage is reduced by 20 points. Level 2: Basic attack

In PHP development, the caching mechanism improves performance by temporarily storing frequently accessed data in memory or disk, thereby reducing the number of database accesses. Cache types mainly include memory, file and database cache. Caching can be implemented in PHP using built-in functions or third-party libraries, such as cache_get() and Memcache. Common practical applications include caching database query results to optimize query performance and caching page output to speed up rendering. The caching mechanism effectively improves website response speed, enhances user experience and reduces server load.
