1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Dear Visitor, we are presently having a membership drive and as a result EVERY new member that registers an account and makes THREE meaningful posts will have a mighty $10,000$ forum credits added to their wallets ... GET YOURS NOW!
    Dismiss Notice
  3. IMSpot.Org is under new management and we look forward to bringing you a range of exciting enhancements in coming days.
    Dismiss Notice
  4. Dear Visitors, why not register an account now and say hello ... we really would love to hear from you?
    Dismiss Notice
  5. Welcome to IMSpot.Org an internet marketing forum and very friendly place for discussion, learning and help in your online endeavours ... please consider joining our internet marketing community and sharing your knowledge with our members.
    Dismiss Notice

How do I implement a simple server side caching system?

Discussion in 'PHP' started by beingchinmay, Jul 21, 2016.

  1. beingchinmay

    beingchinmay An Active Forum Member

    Jun 24, 2015
    Likes Received:
    Now that we have a grasp of the ideas behind output buffering, it’s time to see how we can put this process into action in a manner that will be easy to maintain. To do this, we’ll use a little help from PEAR::Cache_Lite (version 1.1 was used in the examples here).

    As I mentioned, in the interests of keeping your code maintainable and having a reliable caching mechanism, it’s a good idea to delegate the responsibility of caching logic to classes you trust. Cache_Lite provides a solid but easy to use library for caching, handling issues such as file locking, creating, checking for, and deleting cache files, controlling the output buffer, and directly caching the results from function and class method calls. More to the point, Cache_Lite should be relatively easy to apply to an existing application, requiring only minor code modifications.

    There are three main classes in Cache_Lite. First is the base class, Cache_Lite, which deals purely with creating and fetching cache files, but makes no use of output buffering. This class can be used alone for caching operations in which you have no need for output buffering, such as storing the contents of a template
    you’ve parsed with PHP. The examples here will not use Cache_Lite directly, but will instead focus on the two subclasses. Cache_Lite_Function can be usedm to call a function or class method and cache the result; this might prove useful for storing a MySQL query result set, for example. The Cache_Lite_Output class uses PHP’s output control functions to catch the output generated by your script, and store it in cache files; it allows you to perform tasks such as those we completed in the previous solution.
Live Thread addon by sonnb

Share This Page