Home PHP Libraries Other libraries PHP file caching library
PHP file caching library
<?php
class File {
  private $_dir;
  const EXT = '.txt';
  public function __construct() {
    $this->_dir = dirname(__FILE__) . '/files/';
  }
  public function cacheData($key, $value = '', $cacheTime = 0) {
    $filename = $this->_dir  . $key . self::EXT;
    if($value !== '') { // 将value值写入缓存
      if(is_null($value)) {  //$value  为null 将删除缓存
        return @unlink($filename);
      }
      //目录不存在建立目录
      $dir = dirname($filename);
      if(!is_dir($dir)) {
        mkdir($dir, 0777);
      }
      //设置定长缓存时间,保存到缓存文件中
      $cacheTime = sprintf('%011d', $cacheTime);
      return file_put_contents($filename,$cacheTime . json_encode($value));
    }

This is a PHP file caching library, friends who need it can download and use

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

Memcache vs. Memcached: Which PHP Caching Library Should You Choose? Memcache vs. Memcached: Which PHP Caching Library Should You Choose?

12 Nov 2024

Memcache vs. Memcached: Choosing the Right PHP Library for Your Cache NeedsIn the realm of PHP caching libraries, Memcache and Memcached stand out...

Which .NET SFTP Library is Best for Secure File Transfers? Which .NET SFTP Library is Best for Secure File Transfers?

19 Jan 2025

SFTP Libraries for .NET: A Comprehensive AnalysisWhen working with secure file transfer over SSH (SFTP) in .NET applications, choosing the right...

How to Package an Android Library Project into a JAR File? How to Package an Android Library Project into a JAR File?

10 Nov 2024

How to Package an Android Library Project into a JAR FileWhen developing Android applications with multiple modules, sharing libraries between...

How Can I Retrieve and Demangle Symbol Information from a Shared Library (.so file)? How Can I Retrieve and Demangle Symbol Information from a Shared Library (.so file)?

19 Dec 2024

Retrieving Symbol Information from a Shared LibraryWhen working with shared libraries (.so files), it often becomes necessary to examine their...

How to Choose the Right Python Library for Secure File Transfer? How to Choose the Right Python Library for Secure File Transfer?

23 Oct 2024

This article presents two Python libraries (Paramiko and Twisted Conch) for secure file transfer using SFTP. It discusses their features and capabilities, helping developers choose the most suitable library based on their needs, such as simplicity, a

PSR-Caching Interface in PHP PSR-Caching Interface in PHP

11 Jan 2025

Hello everyone! Is your application running slowly due to repetitive database queries? Or have trouble switching between different caching libraries? Let’s dive into PSR-6, the standard that makes caching in PHP predictable and interchangeable! This article is part of the PHPPSR standards series. If you are new to this, you may want to start with PSR-1 basics. What problem does PSR-6 solve? (2 minutes) Before PSR-6, each cache library had its own unique way of working. Want to switch from Memcached to Redis? Rewrite your code. Migrating from one framework to another? Learn the new caching API. PSR-6 solves this problem by providing a common interface that all cache libraries can implement. nuclear

See all articles