dalli 3.0.4 → 3.0.5

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of dalli might be problematic. Click here for more details.

data/lib/dalli.rb CHANGED
@@ -1,33 +1,33 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "dalli/compressor"
4
- require "dalli/client"
5
- require "dalli/ring"
6
- require "dalli/protocol"
7
- require "dalli/protocol/binary"
8
- require "dalli/protocol/server_config_parser"
9
- require "dalli/protocol/ttl_sanitizer"
10
- require 'dalli/protocol/value_compressor'
11
- require "dalli/socket"
12
- require "dalli/version"
13
- require "dalli/options"
14
-
3
+ ##
4
+ # Namespace for all Dalli code.
5
+ ##
15
6
  module Dalli
16
- autoload :Server, "dalli/server"
7
+ autoload :Server, 'dalli/server'
17
8
 
18
9
  # generic error
19
10
  class DalliError < RuntimeError; end
11
+
20
12
  # socket/server communication error
21
13
  class NetworkError < DalliError; end
14
+
22
15
  # no server available/alive error
23
16
  class RingError < DalliError; end
17
+
24
18
  # application error in marshalling serialization
25
19
  class MarshalError < DalliError; end
20
+
26
21
  # application error in marshalling deserialization or decompression
27
22
  class UnmarshalError < DalliError; end
23
+
28
24
  # payload too big for memcached
29
25
  class ValueOverMaxSize < DalliError; end
30
26
 
27
+ # Implements the NullObject pattern to store an application-defined value for 'Key not found' responses.
28
+ class NilObject; end # rubocop:disable Lint/EmptyClass
29
+ NOT_FOUND = NilObject.new
30
+
31
31
  def self.logger
32
32
  @logger ||= (rails_logger || default_logger)
33
33
  end
@@ -38,7 +38,7 @@ module Dalli
38
38
  end
39
39
 
40
40
  def self.default_logger
41
- require "logger"
41
+ require 'logger'
42
42
  l = Logger.new($stdout)
43
43
  l.level = Logger::INFO
44
44
  l
@@ -48,3 +48,20 @@ module Dalli
48
48
  @logger = logger
49
49
  end
50
50
  end
51
+
52
+ require 'dalli/version'
53
+
54
+ require 'dalli/compressor'
55
+ require 'dalli/client'
56
+ require 'dalli/key_manager'
57
+ require 'dalli/ring'
58
+ require 'dalli/protocol'
59
+ require 'dalli/protocol/binary'
60
+ require 'dalli/protocol/server_config_parser'
61
+ require 'dalli/protocol/ttl_sanitizer'
62
+ require 'dalli/protocol/value_compressor'
63
+ require 'dalli/protocol/value_marshaller'
64
+ require 'dalli/protocol/value_serializer'
65
+ require 'dalli/servers_arg_normalizer'
66
+ require 'dalli/socket'
67
+ require 'dalli/options'
@@ -1,17 +1,23 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'rack/session/abstract/id'
3
4
  require 'dalli'
4
5
  require 'connection_pool'
6
+ require 'English'
5
7
 
6
8
  module Rack
7
9
  module Session
10
+ # Rack::Session::Dalli provides memcached based session management.
8
11
  class Dalli < Abstract::Persisted
9
12
  attr_reader :pool
10
13
 
14
+ # Don't freeze this until we fix the specs/implementation
15
+ # rubocop:disable Style/MutableConstant
11
16
  DEFAULT_DALLI_OPTIONS = {
12
- :namespace => 'rack:session',
13
- :memcache_server => 'localhost:11211'
17
+ namespace: 'rack:session',
18
+ memcache_server: 'localhost:11211'
14
19
  }
20
+ # rubocop:enable Style/MutableConstant
15
21
 
16
22
  # Brings in a new Rack::Session::Dalli middleware with the given
17
23
  # `:memcache_server`. The server is either a hostname, or a
@@ -67,7 +73,7 @@ module Rack
67
73
  # for more information about it and its default options (which would only
68
74
  # be applicable if you supplied one of the two options, but not both).
69
75
  #
70
- def initialize(app, options={})
76
+ def initialize(app, options = {})
71
77
  # Parent uses DEFAULT_OPTIONS to build @default_options for Rack::Session
72
78
  super
73
79
 
@@ -80,10 +86,12 @@ module Rack
80
86
  @pool = ConnectionPool.new(popts || {}) { ::Dalli::Client.new(mserv, mopts) }
81
87
  end
82
88
 
83
- def get_session(env, sid)
89
+ def get_session(_env, sid)
84
90
  with_block([nil, {}]) do |dc|
85
- unless sid and !sid.empty? and session = dc.get(sid)
86
- old_sid, sid, session = sid, generate_sid_with(dc), {}
91
+ unless sid && !sid.empty? && (session = dc.get(sid))
92
+ old_sid = sid
93
+ sid = generate_sid_with(dc)
94
+ session = {}
87
95
  unless dc.add(sid, session, @default_ttl)
88
96
  sid = old_sid
89
97
  redo # generate a new sid and try again
@@ -93,7 +101,7 @@ module Rack
93
101
  end
94
102
  end
95
103
 
96
- def set_session(env, session_id, new_session, options)
104
+ def set_session(_env, session_id, new_session, options)
97
105
  return false unless session_id
98
106
 
99
107
  with_block(false) do |dc|
@@ -102,7 +110,7 @@ module Rack
102
110
  end
103
111
  end
104
112
 
105
- def destroy_session(env, session_id, options)
113
+ def destroy_session(_env, session_id, options)
106
114
  with_block do |dc|
107
115
  dc.delete(session_id)
108
116
  generate_sid_with(dc) unless options[:drop]
@@ -124,14 +132,15 @@ module Rack
124
132
  private
125
133
 
126
134
  def extract_dalli_options(options)
127
- raise "Rack::Session::Dalli no longer supports the :cache option." if options[:cache]
135
+ raise 'Rack::Session::Dalli no longer supports the :cache option.' if options[:cache]
128
136
 
129
- popts = {}
130
137
  # Filter out Rack::Session-specific options and apply our defaults
131
- mopts = DEFAULT_DALLI_OPTIONS.merge \
132
- options.reject {|k, _| DEFAULT_OPTIONS.key? k }
138
+ # Filter out Rack::Session-specific options and apply our defaults
139
+ filtered_opts = options.reject { |k, _| DEFAULT_OPTIONS.key? k }
140
+ mopts = DEFAULT_DALLI_OPTIONS.merge(filtered_opts)
133
141
  mserv = mopts.delete :memcache_server
134
142
 
143
+ popts = {}
135
144
  if mopts[:pool_size] || mopts[:pool_timeout]
136
145
  popts[:size] = mopts.delete :pool_size if mopts[:pool_size]
137
146
  popts[:timeout] = mopts.delete :pool_timeout if mopts[:pool_timeout]
@@ -141,20 +150,21 @@ module Rack
141
150
  [mserv, mopts, popts]
142
151
  end
143
152
 
144
- def generate_sid_with(dc)
145
- while true
153
+ def generate_sid_with(client)
154
+ loop do
146
155
  sid = generate_sid
147
- break sid unless dc.get(sid)
156
+ break sid unless client.get(sid)
148
157
  end
149
158
  end
150
159
 
151
- def with_block(default=nil, &block)
160
+ def with_block(default = nil, &block)
152
161
  @pool.with(&block)
153
162
  rescue ::Dalli::DalliError, Errno::ECONNREFUSED
154
- raise if $!.message =~ /undefined class/
163
+ raise if /undefined class/.match?($ERROR_INFO.message)
164
+
155
165
  if $VERBOSE
156
166
  warn "#{self} is unable to find memcached server."
157
- warn $!.inspect
167
+ warn $ERROR_INFO.inspect
158
168
  end
159
169
  default
160
170
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dalli
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.4
4
+ version: 3.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter M. Goldstein
@@ -9,8 +9,22 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-10-27 00:00:00.000000000 Z
12
+ date: 2021-11-30 00:00:00.000000000 Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: connection_pool
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
14
28
  - !ruby/object:Gem::Dependency
15
29
  name: rack
16
30
  requirement: !ruby/object:Gem::Requirement
@@ -26,7 +40,49 @@ dependencies:
26
40
  - !ruby/object:Gem::Version
27
41
  version: '0'
28
42
  - !ruby/object:Gem::Dependency
29
- name: connection_pool
43
+ name: rubocop
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: rubocop-minitest
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: rubocop-performance
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: rubocop-rake
30
86
  requirement: !ruby/object:Gem::Requirement
31
87
  requirements:
32
88
  - - ">="
@@ -55,21 +111,29 @@ files:
55
111
  - lib/dalli/cas/client.rb
56
112
  - lib/dalli/client.rb
57
113
  - lib/dalli/compressor.rb
114
+ - lib/dalli/key_manager.rb
58
115
  - lib/dalli/options.rb
59
116
  - lib/dalli/protocol.rb
60
117
  - lib/dalli/protocol/binary.rb
118
+ - lib/dalli/protocol/binary/request_formatter.rb
119
+ - lib/dalli/protocol/binary/response_processor.rb
120
+ - lib/dalli/protocol/binary/sasl_authentication.rb
61
121
  - lib/dalli/protocol/server_config_parser.rb
62
122
  - lib/dalli/protocol/ttl_sanitizer.rb
63
123
  - lib/dalli/protocol/value_compressor.rb
124
+ - lib/dalli/protocol/value_marshaller.rb
125
+ - lib/dalli/protocol/value_serializer.rb
64
126
  - lib/dalli/ring.rb
65
127
  - lib/dalli/server.rb
128
+ - lib/dalli/servers_arg_normalizer.rb
66
129
  - lib/dalli/socket.rb
67
130
  - lib/dalli/version.rb
68
131
  - lib/rack/session/dalli.rb
69
132
  homepage: https://github.com/petergoldstein/dalli
70
133
  licenses:
71
134
  - MIT
72
- metadata: {}
135
+ metadata:
136
+ rubygems_mfa_required: 'true'
73
137
  post_install_message:
74
138
  rdoc_options: []
75
139
  require_paths:
@@ -78,14 +142,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
78
142
  requirements:
79
143
  - - ">="
80
144
  - !ruby/object:Gem::Version
81
- version: '0'
145
+ version: '2.5'
82
146
  required_rubygems_version: !ruby/object:Gem::Requirement
83
147
  requirements:
84
148
  - - ">="
85
149
  - !ruby/object:Gem::Version
86
150
  version: '0'
87
151
  requirements: []
88
- rubygems_version: 3.2.30
152
+ rubygems_version: 3.2.31
89
153
  signing_key:
90
154
  specification_version: 4
91
155
  summary: High performance memcached client for Ruby