承接 alleyinteractive/wp-psr16 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

alleyinteractive/wp-psr16

Composer 安装命令:

composer require alleyinteractive/wp-psr16

包简介

PSR-16 implementations for WordPress that cache data in the object cache, as transients, as options, and as object metadata.

README 文档

README

This library provides PSR-16 implementations for WordPress projects. It includes adapters for caching data in the object cache, as transients, as options, and as post, term, or other object metadata.

Installation

Install the latest version with:

composer require alleyinteractive/wp-psr16

Basic usage

All the adapters in this library implement the \Psr\SimpleCache\CacheInterface interface and have no other public API apart from their static constructors.

<?php

// Cache data using transients as the datastore.
$transient = \Alley\WP\SimpleCache\Transient_Adapter::create();

// Cache data using the object cache as the datastore.
$object_cache = \Alley\WP\SimpleCache\Object_Cache_Adapter::create();

/*
 * Cache data using options as the datastore. The options are not autoloaded.
 * Using options as the datastore can be slower than using transients or the
 * object cache, but items are never evicted like in Memcache or Redis.
 */
$option = \Alley\WP\SimpleCache\Option_Adapter::create();

/*
 * Cache data using object metadata as the datastore. This allows cache items to
 * be associated with a specific post, term, or other object that supports metadata.
 * For example, you could cache an individual post's related posts. Like options,
 * using metadata as the datastore can be slower, but items are never evicted.
 */
$post_meta   = \Alley\WP\SimpleCache\Metadata_Adapter::for_post( 123 );
$term_meta   = \Alley\WP\SimpleCache\Metadata_Adapter::for_term( 123 );
$user_meta   = \Alley\WP\SimpleCache\Metadata_Adapter::create( 'user', 123 );
$custom_meta = \Alley\WP\SimpleCache\Metadata_Adapter::create( 'custom', 123 );

Implementation details

WordPress returns scalar values in the option and metadata database tables as strings, which is incompatible with PSR-16's requirement that data be returned from the cache "exactly as passed [including] the variable type."

This library works around the default behavior of the database by serializing and unserializing values when they are saved to and retrieved from storage, which has some side effects:

  • Cached items are stored in a custom array structure that includes the serialized value.
  • Cache keys are stored with a prefix to avoid giving the impression that the cache key as passed to the adapter can be used to retrieve the original value using WordPress APIs directly.
  • The custom array structure includes the item's expiration time, which allows option and metadata adapters to support TTLs.

The \Alley\WP\SimpleCache\PSR16_Compliant decorator class is responsible for ensuring PSR-16 compatibility with respect to data types, expiration times, legal cache keys, and other requirements of the specification. You are free to use this decorator with your own cache adapters or with those of another library.

Limitations

  • The transient, option, and metadata adapters do not support the clear() method.
  • The transient, option, and metadata adapters do not support saving binary data. Consult with the provider of your persistent object cache drop-in to determine whether it supports saving binary data.
  • The metadata adapter bypasses type-specific functions like get_post_meta() in favor of underlying functions like get_metadata() for compatibility with other metadata functions like metadata_exists().

About

License

GPL-2.0-or-later

Maintainers

Alley Interactive

alleyinteractive/wp-psr16 适用场景与选型建议

alleyinteractive/wp-psr16 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 13.23k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2024 年 01 月 02 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 alleyinteractive/wp-psr16 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 alleyinteractive/wp-psr16 我们能提供哪些服务?
定制开发 / 二次开发

基于 alleyinteractive/wp-psr16 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

  • Stars: 2
  • Watchers: 17
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-2.0-or-later
  • 更新时间: 2024-01-02