php—Smarty-缓存二(26)
php—Smarty-缓存2(26)
一个页面中,有些数据缓存,有些数据不缓存,就是局部缓存
l $smarty->assign(“var”, “value”, true)
第三个参数:表示是否不缓存
l {$var nocache=true}
在模板变量量后使用nocache参数
l {nocache}{/nocache}
使用一对nocache标记,之间的所有内容不缓存
缓存文件:我们发现姓名被直接写到文件中,年龄每次都需要动态读取,实现局部缓存功能
尝试将name和age的值修改,注意页面上发生的变量,name不变,age改变
七、 单页面多缓存
http://localhost/news.php?id=100
查看id为100的新闻
访问后,会对这个模板生成一个缓存文件,缓存的是id为100的新闻
http://localhost/news.php?id=80
查看id为80的新闻
这时,看到的将是之前的缓存文件
l $smarty->caching=true
开启缓存机制
l $smarty->display(“tpl”, “cacheid”)
第二个参数表示缓存ID,就是某个缓存文件的唯一标准
代码:
我们分别使用这样的url来访问:
Demo07.php?id=10
Demo07.php?id=83
Demo07.php?id=96
然后,发现在缓存目录下,产生这样几个缓存文件:
文件名^之前的内容就是缓存ID,是缓存文件的唯一标识。
清除缓存文件时该如何操作?
$smarty->clearCache(‘demo07.html’);
这样写,表示将demo07模板的所有的缓存文件清除
$smarty->clearCache(‘demo07.html’,83)
这样写,表示将demo07模板对应的ID为83的缓存文件删除
八、 缓存集合
http://localhost/news.php?kid=10&page=8
表示想查看新闻分类id为10的新闻标题,并显示第8页的数据,该如何进行缓存?
l $smarty->caching=true
开启缓存功能
l $smarty->display(“tpl”, $id1.”|”.$id2)
设置缓存ID,并使用 | 进行连接,表示是一个缓存集合
代码:
运行以下url:
Deo08.php?kid=13&page=2
Deo08.php?kid=25&page=8
Deo08.php?kid=2&page=58
发现,在缓存目录下,产生这样几个缓存文件
其实,就是指将得到的所有参数用 | 连接,生成新的缓存文件
MVC中应用Smarty
一、MVC
1、M:模型
2、 V:视图
3、 C:控制器
就是需要用Smarty替换我们之前的View组件

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

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











This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7
