Previously, we explored the PHP cache technology in depth, which mainly referred to the data cache. Data cache mainly refers to the database query cache, each time access to the page, will first detect the corresponding cache data exists, if not exist, connect the database, get data, and the query knot ...
Previously, we explored the PHP cache technology in depth, which mainly referred to the data cache. Data cache mainly refers to the database query cache, each time access to the page, will first detect the corresponding cache data exists, if not exist, connect to the database, get the data, and the query results are serialized after saving to the file, the same query results are directly from the cache table or file.
The most widely used example is the search function of discuz, which caches the result ID into a table and searches the cache table the next time the same keyword is searched.
For a common method, multi-table association, the schedule of the contents of the array is saved to a field in the main table, the need for the array decomposition, the advantage is only read a table, the disadvantage is that two data synchronization will be more than a few steps, the database is always the bottleneck, with the hard disk speed, is the key point.
Page Caching
Each time you visit the page, will detect the corresponding cache page file exists, if not exist, connect to the database, get data, display the page and generate the cache page file at the same time, so the next visit to the page file will play a role. (the template engine and some common caching classes on the Web typically have this feature)
Time-Triggered cache
Check that the file exists and that the timestamp is less than the expiration time of the setting, and if the timestamp of the file modification is greater than the current timestamp minus the expiration timestamp, then cache is used, otherwise the cache is updated.
Content-Triggered caching
Forces the cache to be updated when data is inserted or updated.
Static caching
Static caching refers to static, directly generated HTML or XML and other text files, there is an update when re-generated once, suitable for the less changing pages, this does not say.
Memory Cache
Memcached is a high-performance, distributed memory object caching system for reducing database load and increasing access speed in dynamic applications.
<?php
$memcache = new Memcache;
$memcache->connect (' localhost ', 11211) or Die ("Could not Connect");
$version = $memcache->getversion ();
echo "Server ' s version:". $version. " \ n ";
$tmp _object = new StdClass;
$tmp _object->str_attr = ' Test ';
$tmp _object->int_attr = 123;
$memcache->set (' key ', $tmp _object, False, 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);
?>
Examples of reading libraries:
<?php
$sql = ' SELECT * from users ';
$key = MD5 ($sql); Memcached Object identifiers
if (! ( $datas = $MC->get ($key))) {
The cached data is not fetched in memcached, then the recordset is obtained using a database query
echo "n". Str_pad (' Read datas from MySQL. ', 60, ' _ '). " n ";
$conn = mysql_connect (' localhost ', ' test ', ' test ');
mysql_select_db (' Test ');
$result = mysql_query ($sql);
while ($row = Mysql_fetch_object ($result))
$datas [] = $row;
Saves the result set data obtained in the database to memcached for use on the next visit
$MC->add ($key, $datas);
} else {
echo "n". Str_pad (' Read datas from memcached. ', 60, ' _ '). " n ";
}
Var_dump ($datas);
?>
Buffer for PHP
Like Eaccelerator,apc,phpa,xcache and so on.
MySQL Cache
This is also a non-code level, the classic database is used in this way, look at the following running time, 0.09xxx and so on.
[Client]
......
Default-character-set=gbk
Default-storage-engine=myisam
max_connections=600
max_connect_errors=500
back_log=200
interactive_timeout=7200
query_cache_size=64m
......
table_cache=512
......
myisam_max_sort_file_size=100g
myisam_max_extra_sort_file_size=100g
myisam_sort_buffer_size=128m
key_buffer_size=1024m
read_buffer_size=512m
......
Thread_concurrency=8
Reverse proxy-based Web caching
such as Nginx,squid,mod_proxy (Apache2 and above are divided into mod_proxy and Mod_cache)
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.