New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

wallet

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

wallet

  • 1.0.0.beta.2
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

Wallet

Wallet, a simple ruby DSL for centralizing action cache configuration inside your Rails app.

Installation

Wallet is a gem, available from http://rubygems.org.

Add the following to your Rails 3 app's Gemfile:

gem 'wallet', '~> 1.0.0.beta.2'

Usage

Let's imagine your app has a controller HomeController, and you want to action cache the index action inside of it. First, create a config/wallet.rb inside your rails root, then open your Wallet and add some cash:

Wallet.open do
  cash :home do
    index
  end
end

Next, open your ApplicationController, and add the following into it:

class ApplicationController < ActionController::Base
  include Wallet::Cash
  cash!
end

The cash! method will setup action caching for your controllers (if they have any cache configuration in Wallet).

With this code in place, Rails will action cache the index action inside your home controller for the default TTL (time-to-live) duration: 10 minutes. You can change the default ttl by passing a duration to the default_ttl method:

Wallet.default_ttl = 2.minutes

Now, suppose we have another controller, ArticlesController, and we want to cache the show and index actions on it for a duration of 20 minutes. Simple!

Wallet.open do
  cash :articles, :for => 20.minutes do
    show
    index
  end
end

This will cache only the show and index actions on the ArticlesController.

Now imagine we've added a third action, comments, to our ArticlesController, and we want to cache it for only 1 minute:

Wallet.open do
  cash :articles, :for => 20.minutes do
    show
    index
    comments 1.minute
  end
end

Before filters and action caching

Sometimes, even though an action is cached, you want a before filter to run before Rails try's to serve out the cached response. Authentication is one common use case. You can accomplish this with Wallet by simply calling cash! after the before filters:

class ApplicationController < ActionController::Base
  include Wallet::Cash

  before_filter :authentication
  cash!

  private
  def authentication
    #...
  end
end

Now, the authentication method will run before your before filters.

Engines

Wallet plays nice with engines. If you'd like to use Wallet inside your engine, create a config/wallet.rb file inside your engine, then include Wallet::Railtie inside your Engine railtie:

module Comments class Engine < Rails::Engine include Wallet::Railtie end end

Now, Rails will load the config/wallet.rb inside your engine before your controllers load.

FAQs

Package last updated on 13 Jun 2011

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc