Home PHP Libraries Other libraries PHP useful cache class
PHP useful cache class
 <?php
class Cache
{
    private $dir = "data/cache/";//定义缓存目录
    private $key='c_a_sss'; // 文件名 md5加密 密钥
    function set_dir($dirpath)
    {
        $this->dir=$dirpath;
        $this->make_dir($this->dir);
    }
    function read($key,$minutes=1)
    {
        $filename=$this->get_filename($key);
        if($datas = @file_get_contents($filename))
        {
            $datas = unserialize($datas);
            if(time() - $datas['time'] < $minutes*60)
            {
                return $datas['data'];
            }
        }
        return false;
    }

The cache is the buffer for data exchange (called Cache). When a piece of hardware wants to read data, it will first search for the required data from the cache. If it is found, it will be executed directly. If it cannot be found, it will be executed from the cache. Search in memory. Since the cache runs much faster than the memory, the role of the cache is to help the hardware run faster

Because the cache often uses RAM (non-permanent storage that is lost when power is turned off), so when it is used up In the end, the files will still be sent to storage such as hard drives for permanent storage. The largest cache in a computer is the memory stick. The fastest ones are the L1 and L2 caches built into the CPU. The video memory of the graphics card is a cache for the graphics card's computing chip. There is also a 16M or 32M cache on the hard disk.


Disclaimer

All resources on this site are contributed by netizens or reprinted by major download sites. Please check the integrity of the software yourself! All resources on this site are for learning reference only. Please do not use them for commercial purposes. Otherwise, you will be responsible for all consequences! If there is any infringement, please contact us to delete it. Contact information: admin@php.cn

Related Article

What are some very useful class libraries or tool libraries for PHP? What are some very useful class libraries or tool libraries for PHP?

06 Jul 2016

What are some very useful class libraries or tool libraries for PHP?

How Do I Link Static Libraries That Depend on Other Static Libraries? How Do I Link Static Libraries That Depend on Other Static Libraries?

13 Dec 2024

Linking Static Libraries to Other Static Libraries: A Comprehensive ApproachStatic libraries provide a convenient mechanism to package reusable...

Why Do PHP Developers Use Leading Underscores in Class Methods? Why Do PHP Developers Use Leading Underscores in Class Methods?

11 Nov 2024

Hidden Truths: The Leading Underscore in PHP Class MethodsWhen browsing PHP libraries, one might stumble upon class methods prefixed with a...

laravel - What should the standardized PHP class library naming look like? laravel - What should the standardized PHP class library naming look like?

06 Jul 2016

I have seen many open source projects in the form of class.classname.php, but I have also seen many frameworks in the form of classname.class.php. Where should I place this class? I personally prefer the .class.php form, because in some frameworks, after importing third-party class libraries and specifying class libraries...

Why Do Some PHP Class Methods Start with an Underscore? Why Do Some PHP Class Methods Start with an Underscore?

09 Nov 2024

Why Do Some PHP Class Methods Begin with an Underscore?While exploring PHP libraries, you might have noticed that certain developers prefer to...

How to Silence TensorFlow\'s Debugging Output? How to Silence TensorFlow\'s Debugging Output?

28 Oct 2024

Suppression of Tensorflow Debugging OutputTensorflow prints extensive information about loaded libraries, found devices, and other debugging data...

See all articles