Regarding the use of memcache (entry-level question), memcache has been configured. how can we use it to speed up access?

Source: Internet
Author: User
Regarding the use of memcache (entry-level question), memcache has been configured. how can we use it to speed up access? Example

I read a lot of information online, mostly about memcache configuration installation and function list.

Now echo $ memcache-> getVersion (); can be configured to print the published version.


How to perform further operations to increase the response speed

For example, I already know that a complicated SQL statement has been executed for a long time.

How to operate on this SQL statement?


If the description is not clear enough, please let me describe it as much as possible...

Thank you ~~


Reply to discussion (solution)

I guess you are wrong about the application scenario...

SQL statements are optimized first.

Of course, you can consider putting the table into the temporary memory table for processing.

Example

I read a lot of information online, mostly about memcache configuration installation and function list.

Now echo $ memcache-> getVersion (); can be configured to print the published version.


How to perform further operations to increase the response speed

For example, I already know that a complicated SQL statement has been executed for a long time.

How to operate on this SQL statement?


If the description is not clear enough, please let me describe it as much as possible...

Thank you ~~



Memcache can share the pressure on mysql.
For example, if you have a select read statement to be executed, read from the memcache Cache before each database read, read from mysql if it cannot be read, and write the content to the cache for the next read from the cache.
Memcache can reduce the read pressure on the database service, and it is a cache. the read speed is fast and the load is low.

"For example, I already know that a complicated SQL statement has been executed for a long time." to make it faster, you can only optimize SQL statements.

If this sentence is a read operation, you can write the cache, and it will be very fast to read later.

Note that the cache must be updated during database update and delete operations .~~~

Of course, the optimization should be considered first.

And now we want to cache it faster.

Is set or (and) get in each query?

Isn't that complicated.

Memcache cannot relieve database pressure
If you plan to put the query results in memcache for the next use, will the data you get next time be old?
If you want to check whether the data in the database is updated, what does the cache do?

So what scenarios are memcache suitable?
When your program is already using files or databases to cache intermediate results, using memcache can improve the cache performance.

Memcache cannot relieve database pressure
If you plan to put the query results in memcache for the next use, will the data you get next time be old?
If you want to check whether the data in the database is updated, what does the cache do?

So what scenarios are memcache suitable?
When your program is already using files or databases to cache intermediate results, using memcache can improve the cache performance.



Can I give a specific example to illustrate the application of memcache?

==============
Now I want to query all kinds of information that users are interested in. you need to check the summary of various conditions and then query them in the information summary table. in this case, is memcache suitable for caching the summary results of various conditions and setting an expiration time )?

Cache is mainly used for pages or programs that do not update during a certain period of time and often connect to the database, such as weather forecasts and daily promotion pages of the mall. These accesses will be large and will not be updated for a long time, for example, you can update the data at 8 o'clock every day or divide it into several time periods to view your needs.


Example

I read a lot of information online, mostly about memcache configuration installation and function list.

Now echo $ memcache-> getVersion (); can be configured to print the published version.


How to perform further operations to increase the response speed


For example, I already know that a complicated SQL statement has been executed for a long time.

How to operate on this SQL statement?


If the description is not clear enough, please let me describe it as much as possible...

Thank you ~~



Memcache can share the pressure on mysql.
For example, if you have a select read statement to be executed, read from the memcache Cache before each database read, read from mysql if it cannot be read, and write the content to the cache for the next read from the cache.
Memcache can reduce the read pressure on the database service, and it is a cache. the read speed is fast and the load is low.

"For example, I already know that a complicated SQL statement has been executed for a long time." to make it faster, you can only optimize SQL statements.

If this sentence is a read operation, you can write the cache, and it will be very fast to read later.

Note that the cache must be updated during database update and delete operations .~~~








Is my elder sister a PHP engineer?

Of course, the optimization should be considered first.

And now we want to cache it faster.

Is set or (and) get in each query?

Isn't that complicated.


When your program is already using a file or database to cache intermediate results, the use of memcache can improve the cache performance.

Memcache cannot relieve database pressure
If you plan to put the query results in memcache for the next use, will the data you get next time be old?
If you want to check whether the data in the database is updated, what does the cache do?

So what scenarios are memcache suitable?
When your program is already using files or databases to cache intermediate results, using memcache can improve the cache performance.


When your program is already using files or databases to cache intermediate results, using memcache can improve the cache performance.
This sentence is not understood.

To put it bluntly, Memcache is a memory cache technology and a cache method, which can be used based on the situation.

Memcache can be used to optimize the response speed of your system for data with frequent reads, high read repetition rate, and low data update frequency.

Generally, Memcache can be used in the following steps:

1. instantiate a Memcache object in the code
$ Mem = new Memcache;
$ Mem-> addserver ('127. 0.0.1 ', 127 );

2. after obtaining data, cache the data to Memcache. in the following example, $ data is the data to be cached. $ key can be considered as the unique identifier of the data cached by Memcache.
$ Mem-> add ($ key, $ data, MEMCACHE_COMPRESSED, 60 );

3. when data is required, get data from Memcache based on $ key
$ Val = $ mem-> get ($ key );

In your statement, memcache is not used to optimize SQL statements,

It is used to temporarily store the data obtained after accessing the database. after obtaining the data for the first time, it is stored. you do not need to query the database the next time you access the database. Instead, you can directly retrieve the data from the memory, this reduces the database access pressure.

Memcache is equivalent to an object-oriented access interface (a memory-cached procedural program)

Such logic in code
If ($ mem-> get ('key') {// determines whether the object has been stored
// Stored and retrieved from memory

} Else {
$ Mem-> set ('key', 'value') // no cache saved
}

It's just a simple call. it's still very easy. just give it a try ..

After configuration, the effect is not obvious.

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.