Is PHP a good cache?

Source: Internet
Author: User
Is there any good cache for PHP? for example, if I want to cache the index. php homepage and update it once every 10 minutes, how can I write the cache!
I used to do. net, but now I want to switch to PHP, and many pages need to be cached. I don't know how to write php.

Please have a demo.

For example, if index.php is used, another user will update index.html every 10 minutes. of course, index.html is the cache of index. php,

In time, no index.html is generated,
Index. php is required to update data once every 5 minutes.

How to write !!!

Best generation !!


Reply to discussion (solution)

Use the smarty template. there is a cache in it, http://www.smarty.net/docsv2/en/. there are a few more features in the manual. click here.


Full English

Memcached

What do you do in. net?
It's just a dialect.

Memcached
Memcached cache page? I have never done it. is it because I threw the whole page into a value?

In this scenario, memcached performs caching. Not to mention the amount of communication, you have to load php, read it from the memcached server, and then return it to the client each time a pure static page is generated, which is very inefficient.

The recommended example is to cache the file generated by index.html, and then run the script to update the file regularly.

To cache, you must first know why you want to cache and what you want to cache...

Every answer on the floor is feasible to some extent. The key is what you want to do...

To cache the entire page, you can directly create a static file. Ob_start (), ob_get_contents (), flush (), or ob_flush (). These four functions are sufficient.

When you request this page each time, determine whether the static file exists or the current time-its creation time is greater than or equal to 10 minutes. Then, use the above method to generate a static page. Otherwise, the static file will be read and returned to the browser.

Memcached or redis is suitable for caching data. it is the best method to cache the entire page.

Couch db

Thanks for your help. I tested a page cache and generated an html file. The key is not what I need,
For example, when I query data based on conditions, the cache time is set to 1 minute,

As a result, I select the query condition. The data has not changed.

I want to select the query time, data changes, colleagues, the same query conditions, updated once every minute,
For example, if I select a time zone, the default start time is the data of the last day,
When I select the day before yesterday's condition query, I want the verse of the day before yesterday,
If I re-query the data of the day before yesterday, but the data of the day before yesterday is not updated within one minute, the data will be updated only after one minute,
In one minute, when I select the acquired data, it is the acquired data, not the data of the day before yesterday.

That is, the query condition is changed, and cache is performed for 1 minute, 1 hour, and 1 day according to the condition of the day,
Other condition queries are not affected. of course, other conditions are one minute or one hour. 1-day cache

To put it bluntly, data is cached based on the condition query.

According to your #11 description, your ideas are problematic.
In this case, you need to cache the site at all times since your history. Because anyone can start querying at any time in the past.
It takes at least 6151680 cache items for a period of one minute.
This is obviously not desirable.

Because the available query expressions are limited, you can create several views based on the query expressions. This completes the query operation and the database background.

Yes! That's a headache !!!
So I want to put it in the memory, and then regularly clean up the memory.

Use the input/output buffer to cache files

Newbie, pass ~ I think it is better to use static page cache.

Varnish can cache pages

This is the same as the homepage cache of some website navigation websites. However, they may cache the homepage for a longer period of time on the client, such as one month or three months ......
The specific method is:
1. store the relevant elements referenced on the home page (images, CSS files, and JS files) in a dedicated directory, such as cache;
2. add rules to. htaccess:

# Cache home page objects
# RewriteCond % {HTTP_HOST} ^ www.162100.com [NC]
# RewriteCond % {REQUEST_URI} ^ $ [OR]
# RewriteCond % {REQUEST_URI} ^/$ [OR]
# RewriteCond % {REQUEST_URI} ^/index.html $ [NC]
# RewriteRule (index \. html) gzip. php? Cfile = $1 [L]
# RewriteRule ^ (cache \/. +) $ gzip. php? Cfile = $1 [L]

3) create a file gzip. php in the root directory (that is, a directory with index.html) with the code:

  


Note:
1. write your own URLs in htaccess;
2. the above is my homepage cache client method. I am using it here. I wonder if it will help you. If you don't need it, don't blame me.



In addition, if the cache of the above method takes effect, you can see the cache validity period of the home page and each component in the IE cache folder. if there is a validity period (such as your 10 minutes), the cache takes effect.

When a user browses a static homepage, if the validity period of the static homepage does not exist, it will automatically call the static homepage in the client cache. If the validity period expires, it will be generated again.
This is what I wrote.

That is the entire homepage.

Memcached data cache is suitable for you

Nun memcached

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.