Git Product home page Git Product logo

wallet's Introduction

Introduction

Wallet is a rails gem that allows you to manage all of your action caching configuration in a single yaml file. It supports TTLs.

Motivation

For a large project, it’s nice from a systems administration point of view to be able to quickly manage caching in a single place. Having a central YAML file for managing action caching also opens up the possibility of creating backend web interfaces for your application that could allow site administrators of your app to manage the TTL’s from anywhere.

Installation

To add wallet to your RAILS app, add a config.gem line like the following to the Rails::Initializer section of your environment.rb:

config.gem "wallet", :lib => 'wallet', :version => '>=0.0.3', :source => "http://gemcutter.org"

Then install the missing gem:

bash$ sudo rake gems:install

Lastly, create an initializer that conditionally loads wallet (e.g., RAILS_ROOT/initializers/wallet.rb)

Wallet.load_from_config # will load from RAILS_ROOT/config/wallet.yml by default.

Usage

Once it’s installed, you can create a “wallet.yml” file in your RAILS_ROOT/config directory to manage action caching for your application. Suppose you have a controller “ChannelsController” with actions “cartoon_network” and “current_tv”. At it’s simplest, you could put the following in your “wallet.yml”:

# RAILS_ROOT/config/wallet.yml

channels:
  cartoon_network:
  current_tv:

Wallet would read this file and setup action caching for the cartoon_network and current_tv actions; it would default the TTL on those actions to 60 seconds. If you wanted a different default, you could add a special “default_ttl:” entry to your “wallet.yml”:

# RAILS_ROOT/config/wallet.yml

default_ttl: 30 minutes

channels:
  cartoon_network:
  current_tv:

Noticed that we simple specified “30 minutes”. The format of the ttls is “d\ (minutes?|days?|hours?)”.

Lastly, suppose you wanted current_tv to cache for 5 hours, but cartoon_network to still use the default:

# RAILS_ROOT/config/wallet.yml

default_ttl: 30 minutes

channels:
  cartoon_network: 
  current_tv: 5 hours

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.