Skip to content

Instantly share code, notes, and snippets.

@jhchabran
Created January 14, 2011 10:07
Show Gist options
  • Save jhchabran/779437 to your computer and use it in GitHub Desktop.
Save jhchabran/779437 to your computer and use it in GitHub Desktop.
Little experiment with cache keys
module Cachable
def self.included(receiver)
receiver.class_attribute :cachable
receiver.cachable = Keystore.new
receiver.send(:helper_method, :cachable)
end
class Keystore
def define name, &block
(class << self; self; end).send :define_method, name, &block
end
end
end
# Spec
class Dummy < ApplicationController
include Cachable
end
describe Cachable do
before(:each) do
Dummy.cachable.define :spotlight do |a,b|
"spotlight_#{a}_#{b}"
end
end
it "should generate a key for spotlight" do
Dummy.cachable.spotlight(1,2).should == "spotlight_1_2"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment