0.0
No commit activity in last 3 years
No release in over 3 years
This rubygem does not have a description or summary.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 3.6

Runtime

> 1.0
 Project Readme

SimpleCacher Build Status Gem Version

A very simple use/implement but very useful cacher, use Redis database.

Getting Started

Install via Rubygems

$ gem install simple_cacher

OR ...

Add to your Gemfile

gem 'simple_cacher'

Usage

Use as a home page cache, expired within 120 second.

# The first step is need specify a namespace, one string which should unique each other
# for different purpose, in this current case (one Rails controller action), `request.url'
# is a perfect candidate.
cacher = SimpleCacher.new(namespace: request.url)

if cacher.fresh?(key: 'items')
  @items_hash = cacher.import(key: 'items')
else
  # do something get correct data and assign to a variable items_hash
  @items_hash = cacher.export(key: 'items', data: items_hash, expire: 120)
end

Use as a counter, limit IP access during a time span.

counter = SimpleCacher.new(namespace: 'my_api:sms_log:user_ip')

# Sum IP 123.123.123.123 access count in one day, 
if counter.reach_limit?(key: '123.123.123.123', limit: 5, expire: 86400)
  # if exceed the limit, sent a warn info
else
  # do some sutff
end

Support

worked in MRI 2.[1,2,3,4], the only dependency is redis-rb

Limitations

No known limit.

History

See CHANGELOG for details.

Contributing

  • Bug reports
  • Source
  • Patches:
    • Fork on Github.
    • Run gem install --dev simple_cacher or bundle.
    • Create your feature branch: git checkout -b my-new-feature.
    • Commit your changes: git commit -am 'Add some feature'.
    • Push to the branch: git push origin my-new-feature.
    • Send a pull request :D.

license

Released under the MIT license, See LICENSE for details.