Don't oo every day, this configuration how to change, this piece of code which is wrong, boring, good program is not only the good code, the overall structure is very important to understand more than the program, this article is no longer just the program aspects, will write from the program to the server settings, will be more, but the personal experience is limited, know so much, Do not know I can not write Ah, the article is not good for everyone when I talk in my sleep.
All program examples are from the network
Universal Caching Technology
Data caching: The data cache described here refers to the database query cache, every time you visit the page, you will first detect the existence of the corresponding cached data, if it does not exist, connect the database, get the data, and the query results serialized after the save to the file, the same query results will be directly from the cache table or file.
The broadest example looks at the Discuz search function, caches the result ID in a table, and searches for the cached table the next time the same keyword is searched.
In a common way, when multiple tables are associated, the contents of the table to generate an array to save the main tables in a field, the need to decompose the array, the advantage is to read only a table, the disadvantage is that two data synchronization will be more than a few steps, the database is always a bottleneck, with hard disk for speed, is this key point.
Page Caching:
Every time you visit the page, you will first detect the corresponding cache page file exists, if it does not exist, connect the database, get the data, display the page and generate cached page files, so the next time the page file will play a role. (the template engine and some common online caching classes typically have this feature)
Time Trigger cache:
Check that the file exists and that the timestamp is less than the set expiration time, or update the cache if the timestamp of the file modification is greater than the current timestamp minus the expiration time.
Content Trigger Cache:
Forces an update of the cache when data is inserted or updated.
Static caching
Static caching here refers to static, directly generate HTML or XML and other text files, there are updates to regenerate once, suitable for the page not too changed, this is not said.
The above content is the code level solution, I direct CP other framework, also lazy to change, the content is similar, very easy to do, and will use several ways together, but the following content is the server side of the cache scheme, not code-level, to have a lot of cooperation to do
Memory Cache:
Memcached is a high-performance, distributed memory object caching system for reducing database load and increasing access speed in dynamic applications.
Here's an example of memcached.
<?php
$memcache = new Memcache;
$memcache->connect (' localhost ', 11211) or die ("could not Connect");
$version = $memcache->getversion ();
echo "Server" version: ". $version." \ n ";
$tmp _object = new StdClass;
$tmp _object->str_attr = ' Test ';
$tmp _object->int_attr = 123;
$memcache->set (' key ', $tmp _object, False, All) or Die ("Failed to save data at the server");
echo "Store data in the cache" (data would expire in seconds) \ n ";
$get _result = $memcache->get (' key ');
echo "Data from the cache:\n";
Var_dump ($get _result);
?>