Apps for Smarty Caching

Source: Internet
Author: User
Tags domain name registration
    1. $smarty->cache-dir= "directory name"; Create a cache directory name
    2. $smarty->caching=true; Cache is turned on, false when caching is not valid
    3. $smarty->cache_lifetime=60; Cache time in seconds
Copy Code

Second, the use and elimination of Smarty cache

    1. $marty->display ("Cache.tpl", cache_id); Create a cache with ID
    2. $marty->clear_all_cache (); Clear all Caches
    3. $marty->clear_cache ("index.php"); Clear the cache in index.php
    4. $marty->clear_cache ("index.php", cache_id); Clear cache of the specified ID in index.php
Copy Code

Third, Smarty local cache first: The Insert_ function is not cached by default, this property cannot be modified using the method: Example index.php,

    1. function Insert_get_time () {
    2. Return Date ("y-m-d h:m:s");
    3. }
Copy Code

In Index.html,

    1. {Insert Name= "Get_time"}
Copy Code

The second: Smarty_block defines a block:smarty_block_name ($params, $content, & $smarty) {return $content;}//name represents the zone domain name registration block: $smarty->register_block (' name ', ' Smarty_block_name ', false); The third parameter, False, indicates that the zone is not scripted by the cached template: {name} content {/name} is written as a block plugin: 1) defines a plug-in function: block.cacheless.php, The contents of the plugins directory block.cacheless.php placed in Smarty are as follows:

    1. function smarty_block_cacheless ($param, $content, & $smarty) {
    2. return $content;
    3. }
    4. ?>
Copy Code

2) Writing Program and Template sample program: testcacheless.php

    1. Include (' Smarty.class.php ');
    2. $smarty = new Smarty;
    3. $smarty->caching=true;
    4. $smarty->cache_lifetime = 6;
    5. $smarty->display (' Cache.tpl ');
    6. ?>
Copy Code

Template used: Cache.tpl already cached: {$smarty. Now}
{cacheless} is not cached: {$smarty. now}{/cacheless} Four, custom cache settings Cache_handler_func use a custom function to handle the cache such as:

    1. $smarty->cache_handler_func = "Mycache";
    2. function Mycache ($action, & $smarty _obj, & $cache _content, $tpl _file=null, $cache _id=null, $compile _id=null) {
    3. }
Copy Code

The function is generally rooted in the $action to determine the current operation of the cache:

    1. Switch ($action) {
    2. Case "read"://Read Cache contents
    3. Case "Write"://write Cache
    4. Case "clear"://Empty
    5. }
Copy Code

General use of MD5 ($TPL _file. $cache _id. $compile _id) as the only cache_id if required, use gzcompress and gzuncompress to compress and decompress.

  • Large-Scale Price Reduction
    • 59% Max. and 23% Avg.
    • Price Reduction for Core Products
    • Price Reduction in Multiple Regions
    undefined. /
    Connect with us on Discord
    • Secure, anonymous group chat without disturbance
    • Stay updated on campaigns, new products, and more
    • Support for all your questions
    undefined. /
    Free Tier
    • Start free from ECS to Big Data
    • Get Started in 3 Simple Steps
    • Try ECS t5 1C1G
    undefined. /

    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.