Applications related to smarty cache

Source: Internet
Author: User
Applications related to smarty cache
  1. $ Smarty-> cache-dir = "directory name"; // create a cache directory name
  2. $ Smarty-> caching = true; // enable cache. if it is false, the cache is invalid.
  3. $ Smarty-> cache_lifetime = 60; // cache time, in seconds

II. usage and clearing of Smarty cache

  1. $ Marty-> display ("cache. tpl", cache_id); // create a cache with an 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 the cache of the ID specified in index. php.

3. the first part of the Smarty local cache: the insert _ function is not cached by default. this attribute cannot be modified. in the example of index. php,

  1. Function insert_get_time (){
  2. Return date ("Y-m-d H: m: s ");
  3. }

In index.html,

  1. {Insert name = "get_time "}

The second one: smarty_block defines a block: smarty_block_name ($ params, $ content, & $ smarty) {return $ content ;}// name indicates that the region name registers the block: $ smarty-> register_block ('name', 'smarty _ block_name ', false); // The third parameter false indicates that the region is not written as a cache template: {name} content {/name} is written as the block plug-in: 1) define a plug-in function: block. cacheless. php, put it in the plug-ins directory block of smarty. cacheless. php content is as follows:

  1. Function smarty_block_cacheless ($ param, $ content, & $ smarty ){
  2. Return $ content;
  3. }
  4. ?>

2) compile the 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. ?>

Template used: cache. tpl cached: {$ smarty. now}
{Cacheless} has no cache: {$ smarty. now} {/cacheless} 4. Custom cache settings cache_handler_func:

  1. $ Smarty-> cache_handler_func = "myCache ";
  2. Function myCache ($ action, & $ smarty_obj, & $ cache_content, $ tpl_file = null, $ cache_id = null, $ compile_id = null ){
  3. }

This function usually uses the root action $ action to determine the current cache operation:

  1. Switch ($ action ){
  2. Case "read": // read the cached content
  3. Case "write": // write cache
  4. Case "clear": // clear
  5. }

Generally, md5 ($ tpl_file. $ cache_id. $ compile_id) is used as the unique cache_id. if necessary, gzcompress and gzuncompress can be used for compression and decompression.

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.