Permalink
Browse files

Remove mongo with ttl adapter.

I want to do this differently.
  • Loading branch information...
jnunemaker committed Aug 3, 2012
1 parent 4127007 commit 16122a9147805bc2b551f0196e5e087a69847058
Showing with 0 additions and 80 deletions.
  1. +0 −36 lib/flipper/adapters/mongo_with_ttl.rb
  2. +0 −44 spec/flipper/adapters/mongo_with_ttl_spec.rb
@@ -1,36 +0,0 @@
-require 'set'
-require 'mongo'
-require 'flipper/adapters/mongo'
-
-module Flipper
- module Adapters
- class MongoWithTTL < Mongo
- private
-
- # Override Mongo adapter's load
- def load
- if expired?
- @document = fresh_load
- end
- end
-
- def fresh_load
- @last_load_at = Time.now.to_i
- @collection.find_one(@mongo_criteria) || {}
- end
-
- def ttl
- @options.fetch(:ttl) { 0 }
- end
-
- def expired?
- return true if never_loaded?
- Time.now.to_i >= (@last_load_at + ttl)
- end
-
- def never_loaded?
- @last_load_at.nil?
- end
- end
- end
-end
@@ -1,44 +0,0 @@
-require 'helper'
-require 'flipper/adapters/mongo_with_ttl'
-require 'flipper/spec/shared_adapter_specs'
-
-describe Flipper::Adapters::MongoWithTTL do
- let(:collection) { Mongo::Connection.new.db('testing')['testing'] }
- let(:criteria) { {:_id => id} }
- let(:id) { described_class::DefaultId }
-
- subject { Flipper::Adapters::MongoWithTTL.new(collection) }
-
- before do
- collection.remove(criteria)
- end
-
- it_should_behave_like 'a flipper adapter'
-
- it "can cache document in process for a number of seconds" do
- options = {:ttl => 10}
- adapter = Flipper::Adapters::MongoWithTTL.new(collection, options)
- adapter.write('foo', 'bar')
- now = Time.now
- Timecop.freeze(now)
-
- collection.should_receive(:find_one).with(:_id => id)
- adapter.read('foo')
-
- adapter.read('foo')
- adapter.read('bar')
-
- Timecop.travel(3)
- adapter.read('foo')
-
- Timecop.travel(6)
- adapter.read('foo')
-
- collection.should_receive(:find_one).with(:_id => id)
- Timecop.travel(1)
- adapter.read('foo')
-
- Timecop.travel(4)
- adapter.read('foo')
- end
-end

0 comments on commit 16122a9

Please sign in to comment.