devuri/ob-cache 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

devuri/ob-cache

最新稳定版本:0.1.0

Composer 安装命令:

composer require devuri/ob-cache

包简介

A simple versatile and easy-to-use PHP class designed for managing caching in WordPress environments.

README 文档

README

Overview

The ObCache class is a versatile and easy-to-use PHP class designed for caching in WordPress environments. It provides functionality to manage caching operations with ease, supporting operations such as setting, getting, and removing cached data. This class is particularly useful in scenarios where data retrieval from a cache is preferred over repeatedly querying a database or performing complex computations.

Features

  • Flexible Caching Control: Control whether caching is enabled or disabled.
  • Easy Initialization: Instantiation via a constructor or a static init method.
  • Data Storage and Retrieval: Methods for setting and retrieving cached data.
  • Cache Removal: Functionality to remove specific cache entries.

Usage

Instantiation

Directly via constructor:

$cache = new ObCache();

Using the static init method:

$cache = ObCache::init();

Setting Cache Mode

Enable or disable caching:

$cache->set_cache_allowed(true); // Enable caching
$cache->set_cache_allowed(false); // Disable caching

Setting Data in Cache

Use the set method to cache data:

$cache->set('cache_key', function() {
    // Data generation logic
    return $data;
}, 3600); // 3600 seconds expiration

Retrieving Data from Cache

Use the get method to retrieve or generate and cache data:

$data = $cache->get('cache_key', function() {
    // Data generation logic
    return $data;
}, 3600);

Removing Data from Cache

Use the forget method to remove data from the cache:

$cache->forget('cache_key');

Integration with WordPress

This class utilizes WordPress caching functions (wp_cache_set, wp_cache_get, wp_cache_delete) and is designed to work within a WordPress environment.

Notes

  • The class uses a protected constant OBC_CACHE_GROUP to define a cache group called evp_cached for better organization and management of cached items.
  • Cache mode status can be checked using is_cache_allowed() method.
  • When caching is disabled, the set and get methods directly handle data without caching.

License

This project is licensed under the MIT License - see the LICENSE file for details.

统计信息

  • 总下载量: 3.96k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-12-17

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固