Comments (5)
We noticed this as well and ended up subclassing the Rollout
class to add request-level memoization via the RequestStore gem. There's a probably a better way to do it but this worked well enough for us.
class MemoizedRollout < Rollout
def active?(feature, user = nil)
key = key_for(feature, user)
RequestStore.fetch(key) { super }
end
def activate(feature)
clear_cache(feature)
super
end
def deactivate(feature)
clear_cache(feature)
super
end
def activate_user(feature, user)
clear_cache(feature)
super
end
def deactivate_user(feature, user)
clear_cache(feature)
super
end
private
def clear_cache(feature)
RequestStore.store.keys.each do |key|
next unless key.to_s.start_with?("rollout:#{feature}")
RequestStore.delete(key)
end
end
def key_for(feature, user)
['rollout', feature.to_s, user&.class&.to_s, user&.id].compact.join(':')
end
end
from rollout.
Cool! @jordanfbrown, thanks for sharing!
from rollout.
Rollout isn’t overly public about it but I believe it uses the adapter pattern by only using like two of Redis methods. You can inject anything you like which means you can make a class with same interface that wraps the Redis client with memorization.
from rollout.
Kind what @jordanfbrown did but you shouldn’t need to subclass rollout. You can just define the same interface and initialize with a Redis instance. Your class could be MemoizedRedis. Then you just pass that into Rollout.new. The only other issue with memoization is to turn it on per request or job and ensure it is cleared after. You can do this with middleware or in before action calls in rails. Middleware early in the stack is best.
from rollout.
@jnunemaker Ha thanks!
I was just thinking about how https://github.com/jnunemaker/flipper works when opened the issue here
from rollout.
Related Issues (20)
- Missing release tags HOT 1
- Modulus operator does not create uniformly distributed random numbers HOT 1
- Missing dependency on json HOT 2
- Percentage Rollout on rails view HOT 2
- Google Calendar and iCalendar Integration HOT 3
- Cannot remove a rollout flag from the persistent store HOT 1
- Cronometer of Events HOT 1
- Feature request: to_hash method on Rollout class?
- Activate and Deactive methods work. But activate_user and deactivate_user do not. HOT 1
- check current rollout percentage? HOT 2
- Keyboard TAB marker totally absorbed by certain CSS
- Public Interface for deleting feature entries from Redis HOT 2
- Deprecation warning after upgrading to redis gem version 4.2.0 HOT 5
- Safe to upgrade to 2.5? HOT 1
- Add tag and release for 2.5.0? HOT 2
- Suggest to use a class instead of a global variable for a Rails application HOT 1
- Rollout may break when a group with a | character in the name is activated for a feature with additional data
- Rollout#activate returns false HOT 3
- Redis-rb 5.0+ compatibility HOT 9
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rollout.