infopark_reactor 1.15.0.beta1 → 1.16.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/reactor/cache/permission.rb +17 -19
- data/lib/reactor/cache/user.rb +13 -15
- data/lib/reactor/permission.rb +1 -1
- data/lib/reactor/session/user.rb +4 -0
- data/lib/reactor/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9d51a7c5afd4000ea8e81db0087cc71d2b7dddaf
|
4
|
+
data.tar.gz: ee5eb6afd1de7fb108017e7a82d3bb27f9990acc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d221067cab1005f0735f2cdc346c26b72268281c45a08340158a03716938aead93f94b5da7d58a71263e2b40c20cb3ba5476e9279aa7756b3ae834484e0cce6e
|
7
|
+
data.tar.gz: 880558efbed693fed5b80eab63ce1c479c5b4df8f2d147f5106fd86574e6ad86c81e802b60e2c47f16b1465a234f221d58345bcaff2cdda109e96efdb7b777dd
|
@@ -1,36 +1,34 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
|
-
require 'singleton'
|
3
2
|
|
4
3
|
module Reactor
|
5
4
|
module Cache
|
6
5
|
class Permission
|
7
|
-
|
6
|
+
BACKING_CACHE_EXPIRATION = 5
|
8
7
|
|
9
|
-
def
|
10
|
-
|
11
|
-
get(user, key)
|
8
|
+
def self.instance
|
9
|
+
self.new
|
12
10
|
end
|
13
11
|
|
14
12
|
def initialize
|
15
|
-
|
16
|
-
end
|
17
|
-
|
18
|
-
def invalidate(user)
|
19
|
-
@cache[user] = {}
|
13
|
+
@@backing_storage ||= ActiveSupport::Cache::MemoryStore.new({ size: 1.megabyte })
|
20
14
|
end
|
21
15
|
|
22
|
-
|
23
|
-
|
24
|
-
|
16
|
+
def lookup(user, key, &block)
|
17
|
+
cache_entry = @@backing_storage.fetch(user.to_s, :expires_in => BACKING_CACHE_EXPIRATION.minutes) do
|
18
|
+
{key => block.call}
|
19
|
+
end
|
20
|
+
if cache_entry.key?(key)
|
21
|
+
cache_entry[key]
|
22
|
+
else
|
23
|
+
result = block.call
|
24
|
+
@@backing_storage.write(user.to_s, cache_entry.merge({key => result}), :expires_in => BACKING_CACHE_EXPIRATION.minutes)
|
25
|
+
result
|
26
|
+
end
|
25
27
|
end
|
26
28
|
|
27
|
-
def set(user, key, value)
|
28
|
-
@cache[user] ||= {}
|
29
|
-
@cache[user][key] = value
|
30
|
-
end
|
31
29
|
|
32
|
-
def
|
33
|
-
|
30
|
+
def invalidate(user)
|
31
|
+
@@backing_storage.delete(user.to_s)
|
34
32
|
end
|
35
33
|
end
|
36
34
|
end
|
data/lib/reactor/cache/user.rb
CHANGED
@@ -1,38 +1,36 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
|
-
require 'singleton'
|
3
2
|
|
4
3
|
module Reactor
|
5
4
|
module Cache
|
6
5
|
class User
|
7
|
-
|
6
|
+
BACKING_CACHE_EXPIRATION = 5
|
7
|
+
|
8
|
+
def self.instance
|
9
|
+
self.new
|
10
|
+
end
|
11
|
+
|
12
|
+
def initialize
|
13
|
+
@@backing_storage ||= ActiveSupport::Cache::MemoryStore.new({ size: 1.megabyte })
|
14
|
+
end
|
8
15
|
|
9
16
|
def get(user_name)
|
10
17
|
@cache ||= {}
|
11
18
|
# Rails.logger.debug "User:Cache hit: #{hit?(user_name.to_s)} [#{@cache[user_name.to_s].inspect}]"
|
12
19
|
|
13
20
|
key = user_name.to_s
|
14
|
-
|
15
|
-
|
16
|
-
else
|
17
|
-
@cache[key] = Reactor::Session::User.new(key)
|
21
|
+
@@backing_storage.fetch(key, :expires_in => BACKING_CACHE_EXPIRATION.minutes) do
|
22
|
+
Reactor::Session::User.new(key)
|
18
23
|
end
|
19
24
|
end
|
20
25
|
|
21
26
|
def set(user_name, user)
|
22
|
-
|
23
|
-
@cache[user_name.to_s] = user
|
27
|
+
@@backing_storage.write(user_name.to_s, user, :expires_in => BACKING_CACHE_EXPIRATION.minutes)
|
24
28
|
end
|
25
29
|
|
26
30
|
def invalidate(user_name)
|
27
|
-
|
28
|
-
@cache[user_name.to_s] = nil
|
31
|
+
@@backing_storage.delete(user_name.to_s)
|
29
32
|
end
|
30
33
|
|
31
|
-
private
|
32
|
-
def hit?(user_name)
|
33
|
-
key = user_name.to_s
|
34
|
-
@cache.key?(key) && !@cache[key].nil?
|
35
|
-
end
|
36
34
|
end
|
37
35
|
end
|
38
36
|
end
|
data/lib/reactor/permission.rb
CHANGED
@@ -218,7 +218,7 @@ module Reactor
|
|
218
218
|
|
219
219
|
def granted?(user, permission)
|
220
220
|
user ||= default_user
|
221
|
-
cache.lookup(user, "#{obj.
|
221
|
+
cache.lookup(user, "#{obj.id}:#{permission}") do
|
222
222
|
lookup.superuser?(user) || lookup.send("#{permission}?", user)
|
223
223
|
end
|
224
224
|
end
|
data/lib/reactor/session/user.rb
CHANGED
data/lib/reactor/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: infopark_reactor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.16.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tomasz Przedmojski
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-10-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -225,9 +225,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
225
225
|
version: '0'
|
226
226
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
227
227
|
requirements:
|
228
|
-
- - '
|
228
|
+
- - '>='
|
229
229
|
- !ruby/object:Gem::Version
|
230
|
-
version:
|
230
|
+
version: '0'
|
231
231
|
requirements: []
|
232
232
|
rubyforge_project:
|
233
233
|
rubygems_version: 2.0.14
|