Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/derekstride/jsoncache
A simple JSON cache for caching data intended for use with JSON APIs.
https://github.com/derekstride/jsoncache
cache http json ruby
Last synced: about 2 months ago
JSON representation
A simple JSON cache for caching data intended for use with JSON APIs.
- Host: GitHub
- URL: https://github.com/derekstride/jsoncache
- Owner: DerekStride
- License: mit
- Created: 2015-12-07T17:57:32.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2016-10-09T19:22:02.000Z (about 8 years ago)
- Last Synced: 2024-10-09T09:16:30.757Z (3 months ago)
- Topics: cache, http, json, ruby
- Language: Ruby
- Homepage:
- Size: 69.3 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# JSONCache [![Build Status](https://travis-ci.org/DerekStride/jsoncache.svg?branch=dynamic-caching-based-on-arguments)](https://travis-ci.org/DerekStride/jsoncache)
A simple JSON Cache for use with HTTP APIs.
## Installation
Add this line to your application's Gemfile:
```ruby
gem 'jsoncache'
```And then execute:
```bash
$ bundle
```Or install it yourself as:
```bash
$ gem install jsoncache
```## Usage
Include it in the class or module you want to use it in.
```ruby
extend JSONCache
```To enable caching for a method use the include class method `cache`.
```ruby
cache :expensive_method, expiry: 300
```Note: the `cache` method call has to come after the method definition.
## Example
```ruby
require 'jsoncache'Class A
extend JSONCachedef expensive_method(args)
# code
endcache :expensive_method, expiry: 300
end
```The cache method will the existing method and provide it with caching to the local filesystem. You can set a TTL (time to live) for the cache by setting the `expiry` value in seconds.