With regard to smarty+php development, a little idea of caching and discussion is feasible. Xuzuning Moderator to see

Source: Internet
Author: User
I have developed a program using Php+smarty. Originally when using smarty, knew Smarty has the function of the cache. But I didn't know it at the time. thought that the program development completed the final cache. But now that it's done, start studying the Smarty cache. Discover that Smarty's cache is not for me at all (maybe I didn't study it thoroughly?) )
First of all, smarty once the cache function is turned on, it proves that all pages are cached, and that my program 90% functions are instantaneous. No caching required

Only 10% of the features. such as: Links website Information BANNER These 10 years do not need to change the information needs to be cached. It saves you from querying the table every time.

And Smarty's local cache function is certainly not suitable for me to use. Don't let the 90% function be written as a non-cached tag to call it?
Baidu after a bit of a uniform, certainly no solution (maybe I did not study understand)


Later, I began to study PHP caching technology ... Discover that PHP cannot use IIS application as an ASP to cache

In addition to installing third-party software: Most of them are file caches ..... Then the question came, and, suddenly, I had a strange idea.

Both Smarty and PHP use the file cache in a way that: Why don't I write one,,. Here's how:

function web () {
To make an array of related SQL queries
}
$smarty->assign (' Web ', Web ());
$smarty->display ("web.html");
This is smarty normal parsing ... Well, can we do that?

function web () {
if (when the cache file does not exist) {
Execute SQL query
Generate a TXT document and put an array of queries in it (the first time when the cache file does not exist)
}elseif (the second time the cache file is found here) {
Return opens the TXT document and reads the array from the document;

$smarty->assign (' Web ', Web ());
$smarty->display ("web.html");

}

This is the way I think, I feel that PHP read TXT is certainly faster than the speed of reading the database is right.

Without regard to security
1. Is this feasible?
2. When the data volume is large, will not affect the PHP performance (important)
3. Is there a better way
4.SMARTY can you specify the cache pair Image: None of the others are cached.


Would you please discuss it? Give me an answer.


Reply to discussion (solution)

1, PHP read txt speed must be faster than the speed of reading the database
Does this feel accurate? Because it is not simply read, there are other lines of operation, such as checking whether the file exists, check whether the file is too old .....
2, if the file cache is the query results, then MySQL provided by the Sql_cache clause is more efficient than manipulating the cache file itself?
3, if there is no change in 10 years of information, then why not directly into the static file include?
4, you describe the method and smarty the same, of course, Smarty code is obviously more than yours. But why is that? Very simple, smarty after years of actual combat, his part of the code can handle you have not met, you did not think of the complex situation. When your project runs for a while, the code in the Cache control section will be as fat as you can get.
5. If you consider using third-party memory manipulation software to cache data into memory, should you also consider using MySQL's memory table? At least you don't need to change the original code to manipulate the memory like a table.
6. If your operating environment is a UNIX compatible system, can you consider the Mount memory-based file system?

In short, there is no constant way to improve efficiency, and the best point for the combination of elements is the need to experiment to get

1, PHP read txt speed must be faster than the speed of reading the database
Does this feel accurate? Because it is not simply read, there are other lines of operation, such as checking whether the file exists, check whether the file is too old .....
2, if the file cache is the query results, then MySQL provided by the Sql_cache clause is more efficient than manipulating the cache file itself?
3, if there is no change in 10 years of information, then why not directly into the static file include?
4, you describe the method and smarty the same, of course, Smarty code is obviously more than yours. But why is that? Very simple, smarty after years of actual combat, his part of the code can handle you have not met, you did not think of the complex situation. When your project runs for a while, the code in the Cache control section will be as fat as you can get.
5. If you consider using third-party memory manipulation software to cache data into memory, should you also consider using MySQL's memory table? At least you don't need to change the original code to manipulate the memory like a table.
6. If your operating environment is a UNIX compatible system, can you consider the Mount memory-based file system?

In short, there is no constant way to improve efficiency, and the best point for the combination of elements is the need to experiment to get




1. Just determine if the TXT exists. No time to judge. Because the user modifies the latest data: Can let him clean up the cache (that is, delete the old TXT file)
2. Unable to save the static file as HTML, because my idea is to save the array in txt or to read it in the smarty tag {list} intermediate loop p This array of {/list}
3. I'm going to look into the Sql_cache clause and the MySQL memory table. I am a novice php. Oh, from the ASP turned over

Thank you, moderator.

The Smarty cache is for files, and it is not possible to restrict where the cache is not used, that is, some pages do not turn on caching, and if the volume is large, the memory cache is recommended.

1. Memory table or Memcache
2. Document form

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.