https://github.com/gilbitron/php-simplecache
A simple script for caching 3rd party API calls in PHP
https://github.com/gilbitron/php-simplecache
cache php
Last synced: about 1 month ago
JSON representation
A simple script for caching 3rd party API calls in PHP
- Host: GitHub
- URL: https://github.com/gilbitron/php-simplecache
- Owner: gilbitron
- Created: 2010-05-17T16:22:42.000Z (almost 15 years ago)
- Default Branch: master
- Last Pushed: 2019-10-14T09:35:25.000Z (over 5 years ago)
- Last Synced: 2025-03-28T15:07:17.097Z (about 1 month ago)
- Topics: cache, php
- Language: PHP
- Homepage: https://packagist.org/packages/gilbitron/php-simplecache
- Size: 12.7 KB
- Stars: 262
- Watchers: 31
- Forks: 47
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
Awesome Lists containing this project
README
# PHP SimpleCache
The PHP SimpleCache Class is an easy way to cache 3rd party API calls.
## Install
Install via [composer](https://getcomposer.org):
```javascript
{
"require": {
"gilbitron/php-simplecache": "~1.4"
}
}
```Run `composer install` then use as normal:
```php
require 'vendor/autoload.php';
$cache = new Gilbitron\Util\SimpleCache();
```## Usage
A very basic usage example:
```php
$cache = new Gilbitron\Util\SimpleCache();
$latest_tweet = $cache->get_data('tweet', 'http://search.twitter.com/search.atom?q=from:gilbitron&rpp=1');
echo $latest_tweet;
```A more advanced example:
```php
$cache = new Gilbitron\Util\SimpleCache();
$cache->cache_path = 'cache/';
$cache->cache_time = 3600;if($data = $cache->get_cache('label')){
$data = json_decode($data);
} else {
$data = $cache->do_curl('http://some.api.com/file.json');
$cache->set_cache('label', $data);
$data = json_decode($data);
}print_r($data);
```## Credits
PHP SimpleCache was created by [Gilbert Pellegrom](https://gilbitron.me) from [Dev7studios](https://dev7studios.co). Released under the MIT license.