Skip to content

Uninstall lru_redux and install sin_lru_redux #543

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/splitclient-rb/cache/adapters/cache_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class CacheAdapter
def_delegators :@adapter, :initialize_set, :set_bool, :pipelined

def initialize(config)
@cache = LruRedux::TTL::ThreadSafeCache.new(config.max_cache_size, config.cache_ttl)
@cache = LruRedux::TTL::ThreadSafeCache.new(config.max_cache_size, config.cache_ttl, config.ignore_empty_cache)
@adapter = config.cache_adapter
end

Expand Down
4 changes: 2 additions & 2 deletions lib/splitclient-rb/cache/observers/impression_observer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ class ImpressionObserver
LAST_SEEN_CACHE_SIZE = 500000

def initialize
@cache = LruRedux::TTL::ThreadSafeCache.new(LAST_SEEN_CACHE_SIZE)
@cache = LruRedux::TTL::ThreadSafeCache.new(LAST_SEEN_CACHE_SIZE, true)
@impression_hasher = Hashers::ImpressionHasher.new
end

def test_and_set(impression)
return if impression.nil?

hash = @impression_hasher.process(impression)
previous = @cache[hash]
@cache[hash] = impression[:m]
Expand Down
13 changes: 13 additions & 0 deletions lib/splitclient-rb/split_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class SplitConfig
# @option opts [Int] :impressions_queue_size Size of the impressions queue in the memory repository. Once reached, newer impressions will be dropped
# @option opts [Int] :impressions_bulk_size Max number of impressions to be sent to the backend on each post
# @option opts [#log] :impression_listener this object will capture all impressions and process them through `#log`
# @option opts [Boolean] :ignore_empty_cache (true) The value to enable or disable caching nil values.
# @option opts [Int] :cache_ttl Time to live in seconds for the memory cache values when using Redis.
# @option opts [Int] :max_cache_size Max number of items to be held in the memory cache before prunning when using Redis.
# @return [type] SplitConfig with configuration options
Expand Down Expand Up @@ -70,6 +71,7 @@ def initialize(opts = {})
@machine_name = SplitConfig.machine_hostname(@ip_addresses_enabled, opts[:machine_name], opts[:cache_adapter] || SplitConfig.default_cache_adapter)
@machine_ip = SplitConfig.machine_ip(@ip_addresses_enabled, opts[:machine_ip], opts[:cache_adapter] || SplitConfig.default_cache_adapter)

@ignore_empty_cache = opts[:ignore_empty_cache] || SplitConfig.ignore_empty_cache
@cache_ttl = opts[:cache_ttl] || SplitConfig.cache_ttl
@max_cache_size = opts[:max_cache_size] || SplitConfig.max_cache_size

Expand Down Expand Up @@ -221,6 +223,7 @@ def initialize(opts = {})
attr_accessor :machine_ip
attr_accessor :machine_name

attr_accessor :ignore_empty_cache
attr_accessor :cache_ttl
attr_accessor :max_cache_size

Expand Down Expand Up @@ -591,6 +594,14 @@ def self.transport_debug
false
end

#
# The default ignore_empty_cache value
#
# @return [boolean]
def self.ignore_empty_cache
true
end

#
# The default cache time to live
#
Expand All @@ -599,13 +610,15 @@ def self.cache_ttl
5
end

#
# The default max cache size
#
# @return [int]
def self.max_cache_size
500
end

#
# The default max key size
#
# @return [int]
Expand Down
2 changes: 1 addition & 1 deletion splitclient-rb.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ Gem::Specification.new do |spec|
spec.add_runtime_dependency 'faraday-net_http_persistent', '>= 1.0', '< 3.0'
spec.add_runtime_dependency 'json', '>= 1.8', '< 3.0'
spec.add_runtime_dependency 'jwt', '>= 1.0.0', '< 3.0'
spec.add_runtime_dependency 'lru_redux', '~> 1.1'
spec.add_runtime_dependency 'net-http-persistent', '>= 2.9', '< 5.0'
spec.add_runtime_dependency 'redis', '>= 4.0.0', '< 6.0'
spec.add_runtime_dependency 'sin_lru_redux', '~> 2.5'
spec.add_runtime_dependency 'socketry', '>= 0.4', '< 1.0'
spec.add_runtime_dependency 'thread_safe', '~> 0.3'
end