cache_driver 0.2.0 → 0.2.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6900eb0e5257ce9be8cfd27581a55913564db407
4
- data.tar.gz: 058bd98fd734647c212049c36dab3055cfd38797
3
+ metadata.gz: eb24235fcbfcdb06afee7a91d14c0c517e012e7c
4
+ data.tar.gz: e5b3de59744bf88657d54f3c41ceecbceca65d3e
5
5
  SHA512:
6
- metadata.gz: da4f5b98c439c09b36be99483363dfba17079e10bab35aab08bd4d2cdf8cc0890abeeba7e939e8012f28a7b7d73d86da2b2d7e3e590ed8717e09715cbb26fc71
7
- data.tar.gz: 1eaa73e455951dd5c630be3da769fc28ac06aa0267d4498effcca7a3dbb37d0520fd09d88f41da06cb98ff35c5a65390a2a5b2d91b7b0e8ebc446cca33f5f381
6
+ metadata.gz: d8f3503c9c88ff14000ce1686d1c3d0660aba7bbe553c05990f3afff0248e3e46fcc57b4b6d836c12ab5a840b18683792404ccbb4d4de510a401eb068ac4303c
7
+ data.tar.gz: 4f34d2e450ed91001198ac7dbbf2409e6e08bed40857d017b45ec59432dc6560d3b0102ea789056081396bb23e4b1fbfab510cdffe083cf53c5b73bcac748a1a
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cache_driver (0.2.0)
4
+ cache_driver (0.2.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -58,6 +58,39 @@ cache_model.save! # save this instance to cache
58
58
  cache_model.destroy # delete this instance
59
59
  ```
60
60
 
61
+ Also you can customize the data which you want to cache.
62
+ Just override the two methods below
63
+
64
+ ```ruby
65
+ def to_cache
66
+ # do something you want to cache this model
67
+ end
68
+
69
+ def self.from_cache
70
+ # do something you want to get model from cache
71
+ end
72
+ ```
73
+
74
+ ## Cache Inspect
75
+
76
+ Sometimes you need know the data detail in cache, So you can use a rake task supported by us.
77
+
78
+ $ bundel exec rake cache:inspect
79
+
80
+ Use the the command above to go to cache inspector and you will see the information below
81
+
82
+ CacheDriver >
83
+
84
+ After this you can use the following six commands to do something with the cache set by current project
85
+
86
+ ```sql
87
+ CacheDriver > show models
88
+ CacheDriver > desc <model>
89
+ CacheDriver > select from <model> (where id=<id>)
90
+ CacheDriver > insert to <model> values {'id' => 1, ...}
91
+ CacheDriver > delete from <model> where id=<id>
92
+ ```
93
+
61
94
  ## Contributing
62
95
 
63
96
  Bug reports and pull requests are welcome on GitHub at https://github.com/goshan/cache_driver.
data/lib/cache_driver.rb CHANGED
@@ -4,6 +4,15 @@ require "cache_driver/cache_record"
4
4
  require "cache_driver/cache_util"
5
5
  require "cache_driver/file_cache_util"
6
6
 
7
+
8
+ module CacheDriver
9
+ class Railtie < ::Rails::Railtie
10
+ rake_tasks do
11
+ load 'tasks/cache.rake'
12
+ end
13
+ end
14
+ end
15
+
7
16
  unless CacheDriver.configed?
8
17
  CacheDriver.setup do |config|
9
18
  config.store = :file
@@ -1,3 +1,3 @@
1
1
  module CacheDriver
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
@@ -0,0 +1,120 @@
1
+ namespace :cache do
2
+ desc "inspect cache content"
3
+ task :inspect => :environment do
4
+ show_models = /show models/i
5
+ desc_model = /desc (\S+)/i
6
+ select = /select from (\S+)( where id\s?=\s?(\d+))?/i
7
+ insert = /insert into (\S+) values ({.*})/i
8
+ delete = /delete from (\S+) where id\s?=\s?(\d+)/i
9
+
10
+
11
+ # forbidden stdout info in CacheRecord
12
+ cache_out = StringIO.new
13
+ $stdout = cache_out
14
+
15
+ while true
16
+ $stdout.truncate 0
17
+ STDOUT.print "CacheDriver > "
18
+ cmd = STDIN.gets
19
+ cmd.chomp!
20
+
21
+ if cmd == ""
22
+ next
23
+ elsif cmd == "exit"
24
+ break
25
+ end
26
+
27
+ if cmd =~ show_models
28
+ dir = Dir.new File.expand_path("../../../tmp/cache", __FILE__)
29
+ STDOUT.puts "-------------------------------"
30
+ STDOUT.puts "models: "
31
+ STDOUT.puts "-------------------------------"
32
+ dir.each do |file|
33
+ if file =~ /.+s/i
34
+ STDOUT.puts file[0..-2]
35
+ end
36
+ end
37
+ STDOUT.puts "-------------------------------"
38
+ STDOUT.puts ""
39
+ elsif cmd =~ desc_model
40
+ res = cmd.match desc_model
41
+ clazz = CacheUtil.type_to_class res[1].downcase.to_sym
42
+ ins = clazz.find_all.first
43
+ unless ins
44
+ STDOUT.puts "error: can not find model #{res[1]}"
45
+ next
46
+ end
47
+ STDOUT.puts "-------------------------------"
48
+ STDOUT.puts "attributes: "
49
+ STDOUT.puts "-------------------------------"
50
+ ins.instance_variables.each do |var|
51
+ STDOUT.puts var
52
+ end
53
+ STDOUT.puts "-------------------------------"
54
+ STDOUT.puts ""
55
+ elsif cmd =~ select
56
+ res = cmd.match select
57
+ clazz = CacheUtil.type_to_class res[1].downcase.to_sym
58
+ STDOUT.puts "-------------------------------"
59
+ STDOUT.puts "#{clazz} records: "
60
+ STDOUT.puts "-------------------------------"
61
+ if res[2] # where id = x
62
+ ins = clazz.find_by_id res[3].to_i
63
+ if ins
64
+ STDOUT.print "{"
65
+ ins.instance_variables.each_with_index do |var, index|
66
+ STDOUT.print "#{var} => #{ins.instance_variable_get var}#{index == ins.instance_variables.count ? "" : ", "}"
67
+ end
68
+ STDOUT.print "}\n"
69
+ STDOUT.puts "-------------------------------"
70
+ STDOUT.puts "1 records"
71
+ else
72
+ STDOUT.puts "0 records"
73
+ end
74
+ else # no where
75
+ all_ins = clazz.find_all
76
+ all_ins.each do |ins|
77
+ STDOUT.print "{"
78
+ ins.instance_variables.each_with_index do |var, index|
79
+ STDOUT.print "#{var} => #{ins.instance_variable_get var}#{index == ins.instance_variables.count-1 ? "" : ", "}"
80
+ end
81
+ STDOUT.print "}\n"
82
+ end
83
+ STDOUT.puts "-------------------------------"
84
+ STDOUT.puts "#{all_ins.count} records"
85
+ end
86
+ STDOUT.puts ""
87
+ elsif cmd =~ insert
88
+ res = cmd.match insert
89
+ clazz = CacheUtil.type_to_class res[1].downcase.to_sym
90
+ STDOUT.puts "-------------------------------"
91
+ STDOUT.puts "insert #{clazz} record: "
92
+ STDOUT.puts "-------------------------------"
93
+ ins = clazz.new
94
+ res[2].split(',').each do |assign|
95
+ ele = assign.match /(\S+)\s?=\s?(\S+)/i
96
+ ins.send "#{ele[1]}=", ele[2]
97
+ end
98
+ ins.save!
99
+ STDOUT.puts "inserted record"
100
+ STDOUT.puts "-------------------------------"
101
+ STDOUT.puts ""
102
+ elsif cmd =~ delete
103
+ res = cmd.match delete
104
+ clazz = CacheUtil.type_to_class res[1].downcase.to_sym
105
+ STDOUT.puts "-------------------------------"
106
+ STDOUT.puts "delete #{clazz} record: "
107
+ STDOUT.puts "-------------------------------"
108
+ ins = clazz.find_by_id res[2].to_i
109
+ ins.destroy
110
+ STDOUT.puts "deleted record"
111
+ STDOUT.puts "-------------------------------"
112
+ STDOUT.puts ""
113
+ else
114
+ STDOUT.puts "error: unknow command '#{cmd}'"
115
+ end
116
+ end
117
+
118
+
119
+ end
120
+ end
Binary file
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.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - goshan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-29 00:00:00.000000000 Z
11
+ date: 2016-01-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -58,7 +58,9 @@ files:
58
58
  - lib/cache_driver/config.rb
59
59
  - lib/cache_driver/file_cache_util.rb
60
60
  - lib/cache_driver/version.rb
61
+ - lib/tasks/cache.rake
61
62
  - pkg/cache_driver-0.1.0.gem
63
+ - pkg/cache_driver-0.2.0.gem
62
64
  - tmp/cache/empty
63
65
  homepage: https://github.com/goshan/cache_driver
64
66
  licenses: