jameslevi/nest
Composer 安装命令:
composer require jameslevi/nest
包简介
Is a simple file-based PHP caching library.
README 文档
README
Is a simple file-based PHP caching library.
Features
- Uses PHP's opcache to cache static data.
- Create multiple cache databases.
- Easy integration with any PHP framework or use with no framework at all.
Installation
- You can install via composer.
composer require jameslevi/nest
- If not using any framework, paste the following code to load the autoloader in your project.
require_once __DIR__.'/vendor/autoload.php';
- Import nest into your project.
use Graphite\Component\Nest\Nest;
- Set the default storage path for your project.
Nest::setStoragePath(__DIR__."/storage/cache");
- Set the default hash algorithm to use. The default algorithm is "md5".
Nest::setHashAlgorithm("md5");
Basic Example
Let us try a simple caching for database configuration.
<?php use Graphite\Component\Nest\Nest; // Set the default storage path. Nest::setStoragePath(__DIR__."/storage/cache"); // Set the default hash algorithm. Nest::setHashAlgorithm("md5"); // Create a new nest database instance. $db = new Nest("db"); // Add data to cache. $db->add("host", "localhost"); $db->add("port", 8080); $db->add("username", "root"); $db->add("password", "123"); $db->add("database", "users"); $db->add("charset", "utf-8"); // Generate or update the cache file. $db->write();
This will generate a PHP file with the following content.
<?php return array ( '67b3dba8bc6778101892eb77249db32e' => 'localhost', '901555fb06e346cb065ceb9808dcfc25' => '3306', '14c4b06b824ec593239362517f538b29' => 'root', '5f4dcc3b5aa765d61d8327deb882cf99' => '123', '11e0eed8d3696c0a632f822df385ab3c' => 'users', 'dbd153490a1c3720a970a611afc4371c' => 'utf-8', );
Getting Started
- You can get values using the "get" method.
$db->get("host"); // Returns "localhost".
- You can add new key-value using "add" method.
// Array will be automatically converted into json string. $db->add("tables", array( "user_logs", "user_contacts", "user_address" ));
- You can update key values using "set" method.
$db->set("password", "abc"); // Change the value of password from "123" to "abc".
- All added or updated data will be only saved unless you call the "write" method.
$db->write();
- You can check if a key-value exists using "has" method.
$db->has("charset"); // Returns true because charset exists from our cache.
- You can remove a key-value using "remove" method.
$db->remove("port"); // This will delete port from our cache.
- You can return cache data as array using "toArray" method.
$db->toArray();
- You can return json formatted cache data using "toJson" method.
$db->toJson();
Using Nest Facade
- You can return nest instance by calling a static method that defines the name of your cache database.
Nest::db(); // Is equal to "new Nest('db')"
- You can return key-value by providing the first argument.
Nest::db('charset'); // Will return "utf-8".
- You can update data by providingthe second argument.
Nest::db('username', 'james')->write(); // Will change the value of username from "root" to "james".
- You can add new data by calling "add" method.
Nest::db()->add('token', '1jds9ds93209sdds')->write();
- You can remove key-value using "remove" method.
Nest::db()->remove('token')->write();
Clear Cache
You can clear a cache database using "destroy" method.
Nest::destroy('db');
You can clear all your cache database using "destroyAll" method.
Nest::destroyAll();
Contribution
For issues, concerns and suggestions, you can email James Crisostomo via nerdlabenterprise@gmail.com.
License
This package is an open-sourced software licensed under MIT License.
jameslevi/nest 适用场景与选型建议
jameslevi/nest 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7 次下载、GitHub Stars 达 0, 最近一次更新时间为 2021 年 05 月 03 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「cache」 「caching」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 jameslevi/nest 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 jameslevi/nest 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 jameslevi/nest 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
repository php library
Query caching for Laravel 5
Laravel 5 - Repositories to the database layer
Simple PHP caching system that uses a tmp folder in a Linux environment.
Provides support for PSR-6 compatible cache for Yii1 application
Rinvex Repository is a simple, intuitive, and smart implementation of Active Repository with extremely flexible & granular caching system for Laravel, used to abstract the data layer, making applications more flexible to maintain.
统计信息
- 总下载量: 7
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 8
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-05-03