承接 bigdevwhale/cachetastic 相关项目开发

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

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

bigdevwhale/cachetastic

Composer 安装命令:

composer require bigdevwhale/cachetastic

包简介

A package for caching method results in Laravel

README 文档

README

frankenstein

Cachetastic - Supercharge Your Laravel Caching!

Table of Contents

Introduction

Welcome to Cachetastic, your secret weapon for optimizing caching in Laravel applications. This package supercharges your Laravel caching capabilities, making it a breeze to cache method results and improve your application's performance. Say goodbye to redundant API calls and database queries, and hello to lightning-fast responses!

Key Features

  • Method-Level Caching: Cache the results of any method, whether regular or static, with ease.
  • Flexible Cache Management: Force-refresh and update cache with new values on-demand.
  • Automatic Cache Key Generation: Cache keys are generated based on method name and parameters.
  • Custom Parameter Keys: Users can specify parameter keys for cache key generation.
  • Laravel Integration: Seamlessly integrates with Laravel's caching system.
  • Clean and Elegant Code: Well-structured and efficient codebase for easy use and contribution.
  • PHPUnit and Mockery Ready: Unit testing with PHPUnit and Mockery support included.

Use Cases

Cachetastic is the perfect addition to your Laravel project for various use cases:

  • API Responses: Cache responses from external APIs to reduce latency and minimize rate limits.
  • Database Queries: Cache complex database queries and boost query performance.
  • Expensive Computation: Cache the results of computationally intensive methods for faster execution.
  • Dynamic Content: Cache dynamic content to reduce server load and improve user experience.
  • Rate-Limited APIs: Avoid exceeding rate limits by caching API responses and serving cached data.

Cachetastic is your go-to tool for optimizing your Laravel application's performance in a snap!

Getting Started

Getting started with Cachetastic is a piece of cake. Follow these simple steps to integrate it into your Laravel project:

  1. Install Cachetastic using Composer:

    composer require bigdevwhale/cachetastic
  2. Configure the default cache driver in your Laravel application

  3. Start caching method results with the Cachetastic class.

     // Import the Cachetastic class
     use Cachetastic\Cachetastic;
    
     // Create an instance of Cachetastic
     $cacheService = new Cachetastic(
         new YourApiService(), // The service or object to call the method on.
         'fetchData',          // The name of the method to call on the service.
         [1, 2]               // An array of parameters to pass to the method.
     );
    
     // Customize the cache duration (optional)
     $cacheService->setCacheDuration(60);
    
     // Cache the result of your API call
     $result = $cacheService->retrieveOrCache();
    
      // Force a clear of the cached data if needed
     $cacheService->forceClear();
    
     // Force refresh the cached data with new result
     $result = $cacheService->forceRefresh();
  4. Customize caching, force refresh, and error handling according to your needs.

That's it! Cachetastic seamlessly enhances your caching capabilities with minimal effort.

Constructor Parameters

The Cachetastic constructor requires the following parameters:

  • service: The service or object to call the method on.
  • method: The name of the method to call on the service.
  • params: An array of parameters to pass to the method.

Cache Customization Methods

Cachetastic provides the following methods for customizing caching:

  • setCacheDuration(int $cacheDuration): Set the cache duration in minutes.
  • setCacheKeyParams(array $cacheKeyParams): Set parameter keys to use for cache key generation.
  • setCustomCacheKey(string $customCacheKey): Set a custom cache key to be used instead of generating one.

By default, the cache duration is set to 60 minutes.

You can use these methods to further customize your caching experience.

Example

Here's an example of caching the result of a method in a Laravel application, whether it's a regular or static method:

use Cachetastic\Cachetastic;
use YourApiService;

// Create an instance of Cachetastic to cache the result of a regular method
$cacheService = new Cachetastic(
    new YourApiService(), // The service or object to call the method on.
    'fetchData',          // The name of the method to call on the service.
    [1, 2]               // An array of parameters to pass to the method.
);

// Customize the cache duration (optional)
$cacheService->setCacheDuration(60);

// Cache the result of your API call, whether it's a regular method
$result = $cacheService->retrieveOrCache();

// Create an instance of Cachetastic to cache the result of a static method
$cacheServiceStatic = new Cachetastic(
    YourApiService::class, // The class with the static method.
    'fetchDataStatic',    // The name of the static method to call.
    [1, 2]                // An array of parameters to pass to the static method.
);

// Cache the result of your API call, whether it's a static method
$resultStatic = $cacheServiceStatic->retrieveOrCache();

Overwriting Cache Keys

Please note that if two methods are executed in the same class with only array parameters, they will overwrite each other's cache value since only scalar parameters are used for cache key generation. In this case, consider using the setCustomCacheKey method described above.

Contributing

We welcome contributions from the open-source community. Feel free to submit bug reports, feature requests, or pull requests on our GitHub repository.

License

Cachetastic is open-source software licensed under the MIT License.

Supercharge your Laravel application with Cachetastic and turbocharge your caching game! Give it a try and experience the benefits for yourself. Happy caching!

bigdevwhale/cachetastic 适用场景与选型建议

bigdevwhale/cachetastic 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.13k 次下载、GitHub Stars 达 13, 最近一次更新时间为 2023 年 10 月 27 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 bigdevwhale/cachetastic 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-10-27