简单的页面缓冲技术(一)(转载中文用户)
前言
其实说它为技术,也许不能说是真正的技术。这只不过是我自已想出来的页面处理的方法,当然与别人的想法可能是一致的。不过我还是想给它一个好听的名字。那么我这里所指的页面缓冲是什么呢?就是指将动态生成的页面保存起来,供下一次的使用。这样下一次访问它可能就不需要动态生成了。就象提供了一个cache 一样。在我的网站上,也许你的网站也是如此,使用了象模板之类的技术,这样用户所看到的页面就是动态生成的。但是一个页面对于你是这样,对于别人可能还是这样,即在一段时间内是不会变化的,如果将上次生成的结果直接返回给下一次访问的用户不是更好吗?减少了生成时间,效率要高一些。我想随着网站的发展,速度与效率问题还是要考虑的。这里我给出我的实现,希望对大家有所帮助。只是一个思路,没有具体的实现。
使用条件
是不是所有的网页最好都使用呢?我想不需要,而且也不可能。之所以能缓冲就是因为下一次访问与上一次访问的内容可能是完全一样的。所以对于经常变化的页面就不合适了。比如页面上要显示计数信息的就不太合适。还有就是如果你的动态页面输出时,没有先输出到变量中,而是直接返回给用户,如使用echo,print ,readfile之类的输出,我个人认为现在还作不到。因为无法将输出结果得到,保存到文件中去(反正我是想了半天没有想出有什么可以将直将输出的东西截下来,重定向到文件中去)。那么比较适的动态页面的处理就是:输出结果应该可以放到一个字符串之中。所以使用条件就是:
页面基本不会变化
动态页面的处理结果可以存放到字符串中
这样使用模板类来处理动态页面就很好了。通过在模板中设置可替换的变量,然后根据实际的值替换相应的模板中的变量,同时可以将结果放到字符串中进行输出,这种模板类的处理非常适合保存处理后的页面。当然不使用模板类,也可以通过字符串的处理来生成输出结果也是可行的。至于怎么做就不讨论了。
实现
如前所述,不是一个真正的实现,而是一个实现的思路。
处理流程:
根据访问的要求,生成缓冲文件名
查看文件名是否存在,如果文件不存在,则生成动态页面,将页面保存,同时输出结果,结束;如果存在,则执行第3步
统计文件的修改时间,及与动态页面生成有关的文件的修改时间
比较缓冲文件的修改时间与其它页面的修改时间,如果其它页面修改时间大于缓冲文件修改时间,认为动态结果可能会发生变化,则重新生成动态页面结果,保存到文件中,且输出结果,结束;否则执行第5步
说明缓冲文件最新,则直接输出缓冲文件
这就是我的处理。至于缓冲文件如何保存,可以建一个临时目录也可以使用数据库处理。如果使用了数据库则判断文件是否最新的方式也应作变化,比如在数据库中增加生成时间字段,比较这个时间字段与其它文件的修改时间即可。方法大家自已想。

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

With the rapid development of social media, Xiaohongshu has become one of the most popular social platforms. Users can create a Xiaohongshu account to show their personal identity and communicate and interact with other users. If you need to find a user’s Xiaohongshu number, you can follow these simple steps. 1. How to use Xiaohongshu account to find users? 1. Open the Xiaohongshu APP, click the "Discover" button in the lower right corner, and then select the "Notes" option. 2. In the note list, find the note posted by the user you want to find. Click to enter the note details page. 3. On the note details page, click the "Follow" button below the user's avatar to enter the user's personal homepage. 4. In the upper right corner of the user's personal homepage, click the three-dot button and select "Personal Information"

In Ubuntu systems, the root user is usually disabled. To activate the root user, you can use the passwd command to set a password and then use the su- command to log in as root. The root user is a user with unrestricted system administrative rights. He has permissions to access and modify files, user management, software installation and removal, and system configuration changes. There are obvious differences between the root user and ordinary users. The root user has the highest authority and broader control rights in the system. The root user can execute important system commands and edit system files, which ordinary users cannot do. In this guide, I'll explore the Ubuntu root user, how to log in as root, and how it differs from a normal user. Notice

This article will explain in detail how PHP formats rows into CSV and writes file pointers. I think it is quite practical, so I share it with you as a reference. I hope you can gain something after reading this article. Format rows to CSV and write to file pointer Step 1: Open file pointer $file=fopen("path/to/file.csv","w"); Step 2: Convert rows to CSV string using fputcsv( ) function converts rows to CSV strings. The function accepts the following parameters: $file: file pointer $fields: CSV fields as an array $delimiter: field delimiter (optional) $enclosure: field quotes (

Call of Duty Warzone is a newly launched mobile game. Many players are very curious about how to set the language of this game to Chinese. In fact, it is very simple. Players only need to download the Chinese language pack, and then You can modify it after using it. The detailed content can be learned in this Chinese setting method introduction. Let us take a look together. How to set the Chinese language for the mobile game Call of Duty: Warzone 1. First enter the game and click the settings icon in the upper right corner of the interface. 2. In the menu bar that appears, find the [Download] option and click it. 3. Select [SIMPLIFIEDCHINESE] (Simplified Chinese) on this page to download the Simplified Chinese installation package. 4. Return to the settings

Excel spreadsheet is one of the office software that many people are using now. Some users, because their computer is Win11 system, so the English interface is displayed. They want to switch to the Chinese interface, but they don’t know how to operate it. To solve this problem, this issue The editor is here to answer the questions for all users. Let’s take a look at the content shared in today’s software tutorial. Tutorial for switching Excel to Chinese: 1. Enter the software and click the "File" option on the left side of the toolbar at the top of the page. 2. Select "options" from the options given below. 3. After entering the new interface, click the “language” option on the left

VSCode Setup in Chinese: A Complete Guide In software development, Visual Studio Code (VSCode for short) is a commonly used integrated development environment. For developers who use Chinese, setting VSCode to the Chinese interface can improve work efficiency. This article will provide you with a complete guide, detailing how to set VSCode to a Chinese interface and providing specific code examples. Step 1: Download and install the language pack. After opening VSCode, click on the left

This paper explores the problem of accurately detecting objects from different viewing angles (such as perspective and bird's-eye view) in autonomous driving, especially how to effectively transform features from perspective (PV) to bird's-eye view (BEV) space. Transformation is implemented via the Visual Transformation (VT) module. Existing methods are broadly divided into two strategies: 2D to 3D and 3D to 2D conversion. 2D-to-3D methods improve dense 2D features by predicting depth probabilities, but the inherent uncertainty of depth predictions, especially in distant regions, may introduce inaccuracies. While 3D to 2D methods usually use 3D queries to sample 2D features and learn the attention weights of the correspondence between 3D and 2D features through a Transformer, which increases the computational and deployment time.

Tips for solving Chinese garbled characters written by PHP into txt files. With the rapid development of the Internet, PHP, as a widely used programming language, is used by more and more developers. In PHP development, it is often necessary to read and write text files, including txt files that write Chinese content. However, due to encoding format problems, sometimes the written Chinese will appear garbled. This article will introduce some techniques to solve the problem of Chinese garbled characters written into txt files by PHP, and provide specific code examples. Problem analysis in PHP, text
