Does PHP have no cache? Solution Solutions

Source: Internet
Author: User
Does PHP have no cache?
Really want to do memory cache, non-distributed, is not only in application this object do?

------Solution--------------------
Web-picked PHP cache technology:
Universal Cache Technology
Data cache: The data cache 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 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 cache:
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 cache:
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.
The above content is a code-level solution, I direct CP other framework, too lazy to change, the content is almost, very easy to do, and will be used together in several ways, but the following content is the server-side caching scheme, non-code level, to have multi-party 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:
Code
PHP code
!--? Php$memcache = new Memcache; $memcache--->connec T (' localhost ', 11211) or Die ("Could not Connect"), $version = $memcache->getversion (); echo "Server's version:". $versi On. " \ n "; $tmp _object = new StdClass; $tmp _object->str_attr = ' test '; $tmp _object->int_attr = 123; $memcache->set ('  Key ', $tmp _object, False, Ten) 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);? > 
  • 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.