I never quite understand why memcache is used when smarty is used ~~~~

Source: Internet
Author: User
I never quite understand why memcache is used when smarty is used ~~~~ It is said that the combination of smarty and memcache is a good combination of optimization, but I don't understand why memcache is used when smarty is used ~
Because smarty does not have A page cache. for example, if there is A page A, I set it to be cached for 10 minutes, so it only needs to perform A logical operation every ten minutes. What is memcache used?

Can you give me a small example of how to use smarty and memcache?

Thank you!


Reply to discussion (solution)

The storage space is different. memcache is stored in the memory, and smarty is saved to the hard disk. reading data must be fast from the memory. you can see how these two functions work.

The storage space is different. memcache is stored in the memory, and smarty is saved to the hard disk. reading data must be fast from the memory. you can see how these two functions work.

I know this ..
One color means that memcache is faster than smarty static cache, right?

Since smarty can be cached. Why memcache?

This principle is simple: because of the different operating mechanisms and applicability, smarty is only used by a few junior php programmers, and memcache is widely adopted, and thus a memory-based database system is derived.

Since smarty can be cached. Why memcache?
Is that two types of optimization generally not used together?

This principle is simple: because of the different operating mechanisms and applicability, smarty is only used by a few junior php programmers, and memcache is widely adopted, and thus a memory-based database system is derived.
Ah? Isn't static page cache quite popular now?

One is for data, and the other is for the Accessed page. for example, you can save the queried data to memcache at the longest time, however, if some pages do not require high real-time refresh, the smarty cache takes effect in different scopes, just as if you have eaten carrots and watermelon, and eating carrots increases vitamin C, eating watermelon increases vitamin D. If you are still confused, you don't have to worry about it. you will know it later.

One is for data, and the other is for the Accessed page. for example, you can save the queried data to memcache at the longest time, however, if some pages do not require high real-time refresh, the smarty cache takes effect in different scopes, just as if you have eaten carrots and watermelon, and eating carrots increases vitamin C, eating watermelon increases vitamin D. If you are still confused, you don't have to worry about it. you will know it later.
Well, for example, there is a page that requires a refresh in five minutes. Three of the result sets are obtained from the database.
Then I will set this page to 5-minute static cache update.

For example, isn't memcache used the same?

Reference the reply from the 7 th floor:

One is for data, and the other is for the Accessed page. for example, you can save the queried data to memcache at the longest time, however, if some pages do not require high real-time refresh, the smarty cache takes effect in different scopes, just as if you have eaten carrots and watermelon, and eating carrots increases vitamin C, eating watermelon increases vitamin D. If you are still confused, you don't have to worry about it. you will know it later.

Well, for example, there is a page that requires a 5-minute refresh. There are three of them ......
Different, because even if your page is cached, you need to select the database every time you refresh the page background, but the front page does not change. but if you use memcache, for example, the time is also 5 minutes, in these five minutes, the database will not be queried, which saves database resources. isn't it? the smarty cache just saves the role of parsing template variables, in fact, the relationship between the two is not too large. The only thing in common is cache, and others cannot be compared at all.

Reference reply on the eighth floor:

Reference the reply from the 7 th floor:

One is for data, and the other is for the Accessed page. for example, you can save the queried data to memcache at the longest time, however, if some pages do not require high real-time refresh, the smarty cache takes effect in different scopes, just as if you have eaten carrots and watermelon, and eating carrots increases vitamin C, eating watermelon increases vitamin D. If you are still confused, you don't have to worry about it. you will know it later.

Well, for example, there is a page ,......
Ah ???
Isn't smarty a function that determines whether the current page is cached? is_cached ()
Use it to judge whether the cache has expired, so you don't need to check the database and directly read the static files.

Two different things... as kyzy said. Although it is a cache service, the specific cache objects and implementation methods are not the same. Although the various SM can also be integrated with each other, but it is a little bit off the pants.

Simply put, the final result of the smarty cache is the part in the memcache cache. of course, this is also general, but you can know how much they are not trying to solve the intersection of the same problem.

Smarty's cache is file-based and can be called filecache
File access must be slower than memory access
That's why smarty + memcache
That is to say, you can modify the smarty to put the cache in memcache.

As for what to use and how to use it, it is a solution problem. Independent from implementation technology

Ah ???
Isn't smarty a function that determines whether the current page is cached? is_cached ()
Use it to judge whether the cache has expired, so you don't need to check the database and directly read the static files.

You cannot judge every method.

Well, I understand the differences between the two things. thank you!
However, what I am most confused about is that I don't know under what circumstances the two can work together, just like the example I just mentioned:

There is a page that requires a refresh every five minutes. There are three result sets retrieved from the database.
I set static cache for this page with smarty, and the cache period is 5 minutes.
Then, use the is_cached () method of smarty to determine whether the cache has expired. if the condition is true, you can directly read the static file and obtain the value again.

In this case, even if memcache is used to save these three result sets, isn't it doing anything?
In what circumstances can the two be used together? I just want to know a small example.
Thank you!

Reference the reply from the 10th floor:
Ah ???
Isn't smarty a function that determines whether the current page is cached? is_cached ()
Use it to judge whether the cache has expired, so you don't need to check the database and directly read the static files.


You cannot judge every method.
Do you mean in each controller method?
I think it can be used ~~~~ Is there anything bad about each method?

Actually, it is the difference in the cache storage location. when you determine that the cache can be read by is_cached (), smarty will read the cache. The problem is that the cache is stored on the disk, the disk is slow. when the access volume is large, a large number of disk reads will be blocked, and the system performance will be greatly reduced. in memory, memcache is several orders of magnitude faster than the disk, which is not too congested.

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.