cache_driver 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +20 -0
- data/README.md +36 -8
- data/Rakefile +1 -0
- data/lib/cache_driver/cache_record.rb +7 -2
- data/lib/cache_driver/version.rb +1 -1
- data/pkg/cache_driver-0.1.0.gem +0 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6900eb0e5257ce9be8cfd27581a55913564db407
|
4
|
+
data.tar.gz: 058bd98fd734647c212049c36dab3055cfd38797
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: da4f5b98c439c09b36be99483363dfba17079e10bab35aab08bd4d2cdf8cc0890abeeba7e939e8012f28a7b7d73d86da2b2d7e3e590ed8717e09715cbb26fc71
|
7
|
+
data.tar.gz: 1eaa73e455951dd5c630be3da769fc28ac06aa0267d4498effcca7a3dbb37d0520fd09d88f41da06cb98ff35c5a65390a2a5b2d91b7b0e8ebc446cca33f5f381
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
cache_driver (0.2.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
rake (10.4.2)
|
10
|
+
|
11
|
+
PLATFORMS
|
12
|
+
ruby
|
13
|
+
|
14
|
+
DEPENDENCIES
|
15
|
+
bundler (~> 1.10)
|
16
|
+
cache_driver!
|
17
|
+
rake (~> 10.0)
|
18
|
+
|
19
|
+
BUNDLED WITH
|
20
|
+
1.10.3
|
data/README.md
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
# CacheDriver
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
3
|
+
This gem makes rails model act as ActiveRecord, but not save data into database but cache system, file or redis
|
6
4
|
|
7
5
|
## Installation
|
8
6
|
|
@@ -22,17 +20,47 @@ Or install it yourself as:
|
|
22
20
|
|
23
21
|
## Usage
|
24
22
|
|
25
|
-
|
23
|
+
Your can create a config file to set storage type
|
24
|
+
|
25
|
+
$ touch config/initializers/cache_driver.rb
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
# CacheDriver Config
|
29
|
+
# to make model save data to file or redis not database
|
30
|
+
|
31
|
+
CacheDriver.setup do |config|
|
32
|
+
# set cache store type, :file or :redis
|
33
|
+
# default is :file
|
34
|
+
config.store = :file
|
35
|
+
end
|
36
|
+
```
|
37
|
+
|
38
|
+
And then, create a model file in `app/models`
|
26
39
|
|
27
|
-
|
40
|
+
$ touch app/models/cache_model.rb
|
28
41
|
|
29
|
-
|
42
|
+
Just define model like below
|
30
43
|
|
31
|
-
|
44
|
+
```ruby
|
45
|
+
class CacheModel < CacheRecord
|
46
|
+
end
|
47
|
+
```
|
48
|
+
|
49
|
+
So you can use this model just like other ActiveRecord instance in controllers like
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
cache_models = CacheModel.find_all # get all instance in cache
|
53
|
+
|
54
|
+
cache_model = CacheModel.find_by_id params[:id] # get instance with id
|
55
|
+
|
56
|
+
cache_model.save! # save this instance to cache
|
57
|
+
|
58
|
+
cache_model.destroy # delete this instance
|
59
|
+
```
|
32
60
|
|
33
61
|
## Contributing
|
34
62
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
63
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/goshan/cache_driver.
|
36
64
|
|
37
65
|
|
38
66
|
## License
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -24,10 +24,15 @@ class CacheRecord
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def to_cache
|
27
|
-
self.
|
27
|
+
self.to_json
|
28
28
|
end
|
29
29
|
|
30
30
|
def self.from_cache(str)
|
31
|
-
|
31
|
+
json = JSON.parse str
|
32
|
+
ins = self.new
|
33
|
+
json.each do |key, value|
|
34
|
+
ins.send "#{key}=", value
|
35
|
+
end
|
36
|
+
ins
|
32
37
|
end
|
33
38
|
end
|
data/lib/cache_driver/version.rb
CHANGED
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.
|
4
|
+
version: 0.2.0
|
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-
|
11
|
+
date: 2016-01-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -47,8 +47,10 @@ extensions: []
|
|
47
47
|
extra_rdoc_files: []
|
48
48
|
files:
|
49
49
|
- Gemfile
|
50
|
+
- Gemfile.lock
|
50
51
|
- LICENSE.txt
|
51
52
|
- README.md
|
53
|
+
- Rakefile
|
52
54
|
- cache_driver.gemspec
|
53
55
|
- lib/cache_driver.rb
|
54
56
|
- lib/cache_driver/cache_record.rb
|
@@ -56,6 +58,7 @@ files:
|
|
56
58
|
- lib/cache_driver/config.rb
|
57
59
|
- lib/cache_driver/file_cache_util.rb
|
58
60
|
- lib/cache_driver/version.rb
|
61
|
+
- pkg/cache_driver-0.1.0.gem
|
59
62
|
- tmp/cache/empty
|
60
63
|
homepage: https://github.com/goshan/cache_driver
|
61
64
|
licenses:
|