custom_cache 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/custom_cache.rb +2 -0
- data/lib/custom_cache/acts_as_custom_cache.rb +2 -2
- data/lib/custom_cache/base.rb +2 -0
- data/lib/custom_cache/request_cache.rb +4 -25
- data/lib/custom_cache/scope_cache.rb +22 -0
- data/lib/custom_cache/session_cache.rb +4 -25
- data/lib/custom_cache/version.rb +1 -1
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bcb3efdaa0fcfb3a17bb0bcfaa721361af8ca59a
|
4
|
+
data.tar.gz: 6b994a8583e344be3fa0ec227e66ea96872fd9bf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fc95d67aa049b002d018aa09907eaa21d0a434dbd422e6a281a116814f667379909678f94d32436622b4488320c6d96a442814e9bc56eda6ea3733d2037ae83e
|
7
|
+
data.tar.gz: 308f2049c46368e6de2ffe3b7f59f2ad2cada55a5db85f65d8dcf47138ba14985233dd50933647f04d915563a138f1b18c53c160be7d9305b286f4773f410918
|
data/lib/custom_cache.rb
CHANGED
@@ -9,11 +9,11 @@ module CustomCache
|
|
9
9
|
|
10
10
|
module ClassMethods
|
11
11
|
|
12
|
-
def session_cache
|
12
|
+
def session_cache(options = {})
|
13
13
|
CustomCache::SessionCache.instance
|
14
14
|
end
|
15
15
|
|
16
|
-
def request_cache
|
16
|
+
def request_cache(options = {})
|
17
17
|
CustomCache::RequestCache.instance
|
18
18
|
end
|
19
19
|
|
data/lib/custom_cache/base.rb
CHANGED
@@ -1,36 +1,15 @@
|
|
1
1
|
module CustomCache
|
2
2
|
|
3
|
-
class RequestCache <
|
3
|
+
class RequestCache < ScopeCache
|
4
4
|
|
5
5
|
include Singleton
|
6
6
|
|
7
|
-
attr_accessor :request_id
|
8
|
-
|
9
7
|
def self.create(request_id)
|
10
|
-
|
11
|
-
end
|
12
|
-
|
13
|
-
def cache_key
|
14
|
-
"_request_#{request_id}_cache" if request_id.present?
|
15
|
-
end
|
16
|
-
|
17
|
-
def read(key)
|
18
|
-
if cache_key.present?
|
19
|
-
content = Rails.cache.read(cache_key)
|
20
|
-
content[key] if content.present?
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def write(key, content)
|
25
|
-
if cache_key.present?
|
26
|
-
cached_content = Rails.cache.read(cache_key) || {}
|
27
|
-
cached_content[key] = content
|
28
|
-
Rails.cache.write(cache_key, cached_content)
|
29
|
-
end
|
8
|
+
Thread.current[:request_id] = request_id
|
30
9
|
end
|
31
10
|
|
32
|
-
def
|
33
|
-
|
11
|
+
def scope
|
12
|
+
"_request_#{Thread.current[:request_id]}_cache" if Thread.current[:request_id].present?
|
34
13
|
end
|
35
14
|
|
36
15
|
def self.clear!
|
@@ -2,6 +2,28 @@ module CustomCache
|
|
2
2
|
|
3
3
|
class ScopeCache < Base
|
4
4
|
|
5
|
+
def cached_content
|
6
|
+
Rails.cache.read(self.scope) || {}
|
7
|
+
end
|
8
|
+
|
9
|
+
def read(key)
|
10
|
+
if scope.present? && key.present?
|
11
|
+
cached_content[key] if cached_content.present?
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def write(key, content, options = {})
|
16
|
+
if scope.present? && content.present?
|
17
|
+
cached_content.merge!(key => content)
|
18
|
+
Rails.cache.write(scope, cached_content.merge!(key => content),
|
19
|
+
expires_in: (options[:expires_in] || DEFAULT_EXPIRY))
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def clear
|
24
|
+
Rails.cache.delete(scope) if scope.present?
|
25
|
+
end
|
26
|
+
|
5
27
|
end
|
6
28
|
|
7
29
|
end
|
@@ -1,36 +1,15 @@
|
|
1
1
|
module CustomCache
|
2
2
|
|
3
|
-
class SessionCache <
|
3
|
+
class SessionCache < ScopeCache
|
4
4
|
|
5
5
|
include Singleton
|
6
6
|
|
7
|
-
attr_accessor :session_id
|
8
|
-
|
9
7
|
def self.create(session_id)
|
10
|
-
|
11
|
-
end
|
12
|
-
|
13
|
-
def cache_key
|
14
|
-
"_session_#{session_id}_cache" if session_id.present?
|
15
|
-
end
|
16
|
-
|
17
|
-
def read(key)
|
18
|
-
if cache_key.present?
|
19
|
-
content = Rails.cache.read(cache_key)
|
20
|
-
content[key] if content.present?
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def write(key, content)
|
25
|
-
if cache_key.present?
|
26
|
-
cached_content = Rails.cache.read(cache_key) || {}
|
27
|
-
cached_content[key] = content
|
28
|
-
Rails.cache.write(cache_key, cached_content)
|
29
|
-
end
|
8
|
+
Thread.current[:session_id] = session_id
|
30
9
|
end
|
31
10
|
|
32
|
-
def
|
33
|
-
|
11
|
+
def scope
|
12
|
+
"session#{Thread.current[:session_id]}_cache" if Thread.current[:session_id].present?
|
34
13
|
end
|
35
14
|
|
36
15
|
def self.clear!
|
data/lib/custom_cache/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: custom_cache
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chirag Viradiya
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-11-
|
11
|
+
date: 2014-11-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 4.0.10
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: jquery-rails
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: sqlite3
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|