关于smarty+php开发时,缓存的1点想法与讨论可行性。xuzuning版主来看看
关于smarty+php开发时,缓存的一点想法与讨论可行性。xuzuning版主来看看
我自已用PHP+SMARTY开发一个程序。 本来当时用SMARTY的时候,就知道SMARTY有缓存的功能。但是当时没去了解。以为等程序开发完成了 最后弄缓存。。可是现在开发完了,开始研究SMARTY缓存。发现smarty的缓存 根本不适合我(可能是我没研究透彻?)
首先说一下,smarty一但开启缓存 功能后,就证明所有页面都开始了缓存,, 而我的程序 90%的功能 都是即时性的。不需要缓存
只有10%的功能。如: 友情链接 网站信息 BANNER 这些10年都不用改一次的信息 需要缓存起来。省得每次都查询表。
而SMARTY的局部缓存功能 肯定不适合我去用。总不能 让这90%的功能 都写成一个不缓存标签 去调用吧?
百度一下过后 千篇一律, 肯定没有解决方法(可能是我没研究明白)
后来 又开始研究 PHP的缓存技术。。。发现PHP 不能像ASP一样 利用IIS application来缓存
除了安装第三方软件外。。大多数 都是文件缓存。。。。。。。。那么问题来了,,,我突然产生了一个奇怪的想法。
即然 SMARTY和PHP 都是利用文件缓存的方式。。为什么我不自已写一个,,。。 方法如下:
function web(){
相关SQL查询 组成数组
}
$smarty->assign('web',web());
$smarty->display("web.html");
这是smarty正常的解析 。。。那我们可不可以这样
function web(){
if(当缓存文件不存在){
执行SQL查询
生成一个TXT文档 并把查询的数组放在里面(第一次 当缓存文件不存在时)
}elseif (第二次 这里就发现了缓存文件){
return 打开TXT文档 并读取文档中的数组;
}
$smarty->assign('web',web());
$smarty->display("web.html");
}
这是我想到的办法,, 我感觉 PHP读取TXT的速度 肯定 比读取数据库的速度要快 对不对。
在不考虑安全性的情况下
1.这样做 是否可行?
2.在数据量大的时候,会不会影响PHP性能(重要)
3.还有没有更好的办法
4.SMARTY 可不可以指定缓存对像。。其它都不缓存。
请大家讨论一下。给我个答案吧。
------解决思路----------------------
1、PHP读取TXT的速度 肯定 比读取数据库的速度要快
这个感觉准确吗?因为实际上并不是单纯的读,还要有其他行管的操作,比如检查文件是否存在,检查文件是否太旧了.....
2、如果文件缓存的是查询结果,那么 mysql 提供的 SQL_CACHE 子句是否比自己操纵缓存文件效率更高些呢?
3、如果有10年都不用改一次的信息,那么为何不直接做成静态文件 include 进来呢?
4、你描述的方法与 smarty 的如出一辙,当然 smarty 的代码显然要比你的多。但那又是为什么呢?很简单,smarty 经过多年的实战,他那部分代码能处理你没遇到过的、你没想到的复杂情况。当你的项目经过一段时间运行以后,缓存控制部分的代码也会一样的胖起来的
5、如果你考虑使用第三方内存操作软件来缓存数据到内存的话,那么是否也应该考虑使用 mysql 的内存表呢?至少不需要改变原有代码就可象操作表一样操作内存了
6、如果你的运行环境是 unix 兼容系统,是否也可考虑 mount 基于内存的文件系统呢
总之提高效率并没有一成不变的方法,而各种元素的组合的最佳点是需要实验才能得到的

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



PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

If you are an experienced PHP developer, you might have the feeling that you’ve been there and done that already.You have developed a significant number of applications, debugged millions of lines of code, and tweaked a bunch of scripts to achieve op

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,

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

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.

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.
