fofx / api-cache
Laravel-based API response caching library
Requires
- php: ^8.3
- fofx/helper: ^1.1
- guzzlehttp/guzzle: ^7.9
- jeremykendall/php-domain-parser: ^6.3
- laravel/framework: ^11.38|^12.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.68
- orchestra/testbench: ^9.9
- phpdocumentor/graphviz: ^2.1
- phpdocumentor/reflection: ^6.3
- phpstan/phpstan: ^2.1
- phpstan/phpstan-mockery: ^2.0
- phpunit/phpunit: ^11.5
- dev-master
- v1.2.4
- v1.2.3
- v1.2.2
- v1.2.1
- v1.2.0
- v1.1.9
- v1.1.8
- v1.1.7
- v1.1.6
- v1.1.5
- v1.1.4
- v1.1.3
- v1.1.2
- v1.1.1
- v1.1.0
- v1.0.9
- v1.0.8
- v1.0.7
- v1.0.6
- v1.0.5
- v1.0.4
- v1.0.3
- v1.0.2
- v1.0.1
- v1.0.0
- v0.9.9
- v0.9.8
- v0.9.7
- v0.9.6
- v0.9.5
- v0.9.4
- v0.9.3
- v0.9.2
- v0.9.1
- v0.9.0
- v0.8.9
- v0.8.8
- v0.8.7
- v0.8.6
- v0.8.5
- v0.8.4
- v0.8.3
- v0.8.2
- v0.8.1
- v0.8.0
- v0.7.9
- v0.7.8
- v0.7.7
- v0.7.6
- v0.7.5
- v0.7.4
- v0.7.3
- v0.7.2
- v0.7.1
- v0.7.0
- v0.6.9
- v0.6.8
- v0.6.7
- v0.6.6
- v0.6.5
- v0.6.4
- v0.6.3
- v0.6.2
- v0.6.1
- v0.6.0
- v0.5.9
- v0.5.8
- v0.5.7
- v0.5.6
- v0.5.5
- v0.5.4
- v0.5.3
- v0.5.2
- v0.5.1
- v0.5.0
- v0.4.9
- v0.4.8
- v0.4.7
- v0.4.6
- v0.4.5
- v0.4.4
- v0.4.3
- v0.4.2
- v0.4.1
- v0.4.0
- v0.3.9
- v0.3.8
- v0.3.7
- v0.3.6
- v0.3.5
- v0.3.4
- v0.3.3
- v0.3.2
- v0.3.1
- v0.3.0
- v0.2.9
- v0.2.8
- v0.2.7
- v0.2.6
- v0.2.5
- v0.2.4
- v0.2.3
- v0.2.2
- v0.2.1
- v0.2.0
- v0.1.9
- v0.1.8
- v0.1.7
- v0.1.6
- v0.1.5
- v0.1.4
- v0.1.3
- v0.1.2
- v0.1.1
- v0.1.0
- v0.0.9
- v0.0.8
- v0.0.7
- v0.0.6
- v0.0.5
- v0.0.4
- v0.0.3
- v0.0.2
- v0.0.1
This package is auto-updated.
Last update: 2025-08-08 01:49:15 UTC
README
A Laravel-based PHP library for caching API responses from various services (OpenAI, DataForSEO, Pixabay, YouTube, and more). Provides intelligent caching, rate limiting, compression, and response management through a unified interface.
Requirements
- PHP 8.3+
- Laravel 11.38+
- Redis (for distributed rate limiting)
Development Setup
- Clone the repository
- Install dependencies:
composer install
- Copy
.env.example
to.env
- For testing the demo API:
php -S 0.0.0.0:8000 -t public
Documentation
Please see the docs folder for:
- Laravel Integration Guide - How to use this library in a full Laravel project
- Usage - Basic setup guide
- Database Migrations - Explanation of unconventional approach to database migrations
- Rate Limiting - Rate limiting with Redis
- Cloudflare Tunnel - Usage of Cloudflare Tunnel for local development
Diagrams
Features
- API response caching
- Rate limiting with Redis
- Compression support
- Multiple API client support
Caching Control
The sendCachedRequest()
method respects the caching settings of the API client. You can control caching behavior using:
// Create a new client instance $client = new ScraperApiClient(); // Disable caching for a specific request $client->setUseCache(false); // Check current caching status $isCachingEnabled = $client->getUseCache(); echo 'Is caching enabled: ' . ($isCachingEnabled ? 'true' : 'false') . PHP_EOL; $response = $client->scrape('https://httpbin.org/headers'); echo format_api_response($response, true); // Re-enable caching $client->setUseCache(true);
Rate Limiting
Redis-based distributed rate limiting is implemented to ensure consitent rate limiting across multiple application instances.
See Rate Limiting Documentation for details.
Database Migrations
This library takes an unconventional approach to database migrations in order to follow the DRY principle and simplify maintenance across multiple clients, while maintaining consistency between tables.
For more details, see Database Migrations Documentation.
Laravel Integration
To use this library in a full Laravel project, see the Laravel Integration Guide for step-by-step setup instructions including installation, configuration, and usage examples.
Usage
Getting Started
- Usage Introduction - Basic setup and usage guide
API Clients
DataForSEO API
- DataForSEO Setup
- DataForSEO Webhooks
- SERP Google Organic
- SERP Google Autocomplete
- Keywords Data Google Ads
- Labs
- Labs Google
- Merchant Amazon Products
- Merchant Amazon ASIN
- On Page
- Backlinks
- Backlinks Bulk
Utilities
- Responses Table Converters - Can be used to convert between compressed and uncompressed response tables
License
MIT