cache_driver 0.3.9 → 0.3.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +9 -8
- data/lib/cache_driver.rb +4 -0
- data/lib/cache_driver/cache_util.rb +20 -4
- data/lib/cache_driver/config.rb +5 -1
- data/lib/cache_driver/version.rb +1 -1
- data/lib/tasks/cache.rake +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 83371e1ab12f3e086f893476da1bf9b682abefd2
|
4
|
+
data.tar.gz: 3a262668fc006349500c77694f8a48183498914d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5b33e77d7d62fe6ac9a97ca368bfd44b26087511ee8a55964f926bbc580e38d9d955d1b359b5e40a7368ab37902f0b090c511c0998ded8890f13ead5112b5780
|
7
|
+
data.tar.gz: af4d9a0f1d49f0aeee72a6106141e30dadcaa0a9f4922047e05368d6d92a498ddd11b8ae219b71f3a90a3a63311b586d7a9a756b69433fc38ae80ac061c5fd18
|
data/README.md
CHANGED
@@ -78,7 +78,7 @@ end
|
|
78
78
|
|
79
79
|
def self.from_cache(obj)
|
80
80
|
# super will return a new instance for this class from a HashMap named `obj` which unserialized from cache, and the key of HashMap is String not Symbol.
|
81
|
-
# Only Fixnum, String, Array, Hash can be unserialized into
|
81
|
+
# Only Fixnum, String, Array, Hash can be unserialized into HashMap exactly
|
82
82
|
# do other work with this new instance to customize way of unserialization
|
83
83
|
# return a instance of this Class which is unserialized from cache
|
84
84
|
ins = super obj
|
@@ -89,7 +89,7 @@ end
|
|
89
89
|
|
90
90
|
Sometimes you need know the data detail in cache, So you can use a rake task supported by us.
|
91
91
|
|
92
|
-
$
|
92
|
+
$ bundle exec rake cache:inspect
|
93
93
|
|
94
94
|
Use the the command above to go to cache inspector and you will see the information below
|
95
95
|
|
@@ -98,12 +98,13 @@ Use the the command above to go to cache inspector and you will see the informat
|
|
98
98
|
After this you can use the following six commands to do something with the cache set by current project
|
99
99
|
|
100
100
|
```sql
|
101
|
-
CacheDriver > ?
|
102
|
-
CacheDriver > show models
|
103
|
-
CacheDriver > show keys <model>
|
104
|
-
CacheDriver > find <model> in <key>
|
105
|
-
CacheDriver > save <model> to <key> withs <attr1>=<val1>,<attr2>=<val2>,...
|
106
|
-
CacheDriver > delete <model> in <key>
|
101
|
+
CacheDriver > ? # show all commands and descriptions
|
102
|
+
CacheDriver > show models # list all models
|
103
|
+
CacheDriver > show keys <model> # list all keys of model in cache
|
104
|
+
CacheDriver > find <model> in <key> # fetch data of model with key
|
105
|
+
CacheDriver > save <model> to <key> withs <attr1>=<val1>,<attr2>=<val2>,... # update data of model, create one if not existed
|
106
|
+
CacheDriver > delete <model> in <key> # delete data of model
|
107
|
+
CacheDriver > clear <model> # delte all data of model
|
107
108
|
```
|
108
109
|
|
109
110
|
## Contributing
|
data/lib/cache_driver.rb
CHANGED
@@ -2,19 +2,35 @@ class CacheUtil
|
|
2
2
|
|
3
3
|
class << self
|
4
4
|
def write(type, key, data)
|
5
|
-
|
5
|
+
if CacheDriver.logger
|
6
|
+
CacheDriver.logger.debug "[CACHE] save #{type} ##{key} to cache"
|
7
|
+
else
|
8
|
+
puts "[CACHE] save #{type} ##{key} to cache"
|
9
|
+
end
|
6
10
|
end
|
7
11
|
|
8
12
|
def read(type, key)
|
9
|
-
|
13
|
+
if CacheDriver.logger
|
14
|
+
CacheDriver.logger.debug "[CACHE] get #{type} ##{key} from cache"
|
15
|
+
else
|
16
|
+
puts "[CACHE] get #{type} ##{key} from cache"
|
17
|
+
end
|
10
18
|
end
|
11
19
|
|
12
20
|
def read_all(type)
|
13
|
-
|
21
|
+
if CacheDriver.logger
|
22
|
+
CacheDriver.logger.debug "[CACHE] get all #{type} from cache"
|
23
|
+
else
|
24
|
+
puts "[CACHE] get all #{type} from cache"
|
25
|
+
end
|
14
26
|
end
|
15
27
|
|
16
28
|
def delete(type, key)
|
17
|
-
|
29
|
+
if CacheDriver.logger
|
30
|
+
CacheDriver.logger.debug "[CACHE] delete #{type} ##{key} from cache"
|
31
|
+
else
|
32
|
+
puts "[CACHE] delete #{type} ##{key} from cache"
|
33
|
+
end
|
18
34
|
end
|
19
35
|
|
20
36
|
# type --> :room
|
data/lib/cache_driver/config.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module CacheDriver
|
2
2
|
class Config
|
3
|
-
attr_accessor :store, :file_dir, :redis_host, :redis_port, :redis_namespace
|
3
|
+
attr_accessor :store, :file_dir, :redis_host, :redis_port, :redis_namespace, :logger
|
4
4
|
end
|
5
5
|
|
6
6
|
@@config = Config.new
|
@@ -21,6 +21,10 @@ module CacheDriver
|
|
21
21
|
@@config.store == :redis
|
22
22
|
end
|
23
23
|
|
24
|
+
def self.logger
|
25
|
+
@@config.logger
|
26
|
+
end
|
27
|
+
|
24
28
|
def self.setup
|
25
29
|
yield @@config
|
26
30
|
end
|
data/lib/cache_driver/version.rb
CHANGED
data/lib/tasks/cache.rake
CHANGED
@@ -18,7 +18,7 @@ class CacheDriverClient
|
|
18
18
|
end
|
19
19
|
elsif @cli.class == Redis
|
20
20
|
models = @cli.keys.map do |key|
|
21
|
-
key.gsub("#{CacheDriver.config.redis_namespace}:", '').gsub(/#.+/, '')
|
21
|
+
key.gsub("#{CacheDriver.config.redis_namespace}:", '').gsub(/#.+/, '')[0..-2]
|
22
22
|
end.uniq
|
23
23
|
end
|
24
24
|
models.sort
|
@@ -173,7 +173,7 @@ namespace :cache do
|
|
173
173
|
prompt.say "find <model> in <key> | fetch data of model\n"
|
174
174
|
prompt.say "save <model> to <key> withs <attr1>=<val1>,... | update data of model, create one if not existed\n"
|
175
175
|
prompt.say "delete <model> in <key> | delete data of model\n"
|
176
|
-
prompt.say "clear <model> | delete data of model\n"
|
176
|
+
prompt.say "clear <model> | delete all data of model\n"
|
177
177
|
prompt.say "------------------------------------------------------------------------------------------------\r"
|
178
178
|
when :show_models
|
179
179
|
prompt.say "Models: \r".on_green.bold
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cache_driver
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- goshan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-02-
|
11
|
+
date: 2019-02-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|