easy_cache 0.0.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a7e12c249c9d5282beb1b5ab61fda6e2e158ed01
4
+ data.tar.gz: e7a87df9e71cc3f64161cff970c4284b51686dce
5
+ SHA512:
6
+ metadata.gz: 6afdd3972907a9a70af3300550ecfb66a55f87aa173d614a83d4e73607eea9dba032cc109d51285fccd70c71aaace415313ac44dc790840c26947fc6ccd7bac2
7
+ data.tar.gz: 28dba49cea5db4b2b78e476121a15edec97d4e90adc97d27ce05d6f8a54d20ce11014b89fe9a7b7dea7aa334d4b3ed1bf56994ca519b3d938dde8fb13f8e9e58
@@ -0,0 +1,42 @@
1
+ EasyCache is a way to easily cache method calls to a readable YAML file.
2
+
3
+ Internally it uses the [gemmy](http://github.com/maxpleaner/gemmy) library I made.
4
+
5
+ Specifically, the PersistedHash (which syncs a hash's state to YAML file) is
6
+ extended with a `get_or_set(key, &blk)` method where the block result gets cached as `key`.
7
+
8
+ The return value of `get_or_set` is the block result. So it can easily be placed as a wrapper
9
+ around any synchronous method:
10
+
11
+ ```rb
12
+
13
+ require 'easy_cache'
14
+ # The ~/gemmy path will be automatically created
15
+ # However the cache path can be overridden with:
16
+ # ENV["GEMMY_CACHE_PATH"]
17
+
18
+ my_method_cad(arg)
19
+ my_method_cache.get_or_set(arg) do
20
+ "#{arg} result is saved"
21
+ end
22
+ end
23
+
24
+ def my_method(arg)
25
+ my_method_cache.get_or_set(arg) do
26
+ "#{arg} result is saved"
27
+ end
28
+ end
29
+ ```
30
+
31
+ There are other methods in the API, too.
32
+
33
+ - `#clear`
34
+ - `#set_state(hash)`
35
+ - `#get(*nested_keys)`
36
+ - `#set(*nested_keys, val)`
37
+ - `#data` (the entire state)
38
+
39
+ Note that `[]` and `[]=` only interact with the in-memory hash. They don't touch the YAML file.
40
+
41
+
42
+
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ require 'easy_cache'
3
+ class EasyCache::CLI < Thor
4
+ desc "test", "run tests"
5
+ def test
6
+ puts "No tests have been wrritten"
7
+ exit
8
+ end
9
+ end
10
+ EasyCache::CLI.start ARGV
@@ -0,0 +1,25 @@
1
+ require 'gemmy'
2
+
3
+ class EasyCache
4
+
5
+ module HashPatch
6
+ def cache(db_name)
7
+ EasyCacheModule.cache self, db_name
8
+ end
9
+
10
+ def self.cache(hash, db_name)
11
+ Gemmy.component("cache").new db_name
12
+ end
13
+
14
+ refine Hash do
15
+ include HashPatch
16
+ end
17
+ end
18
+
19
+ def self.new(hash={}, db_name)
20
+ HashPatch.cache hash, db_name
21
+ end
22
+
23
+ end
24
+
25
+ Gem.find_files("easy_cache/**/*.rb").each &method(:require)
@@ -0,0 +1,3 @@
1
+ module EasyCache
2
+ VERSION = '0.0.1'
3
+ end
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: easy_cache
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - maxpleaner
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-12-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: gemmyrb
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: ''
28
+ email: maxpleaner@gmail.com
29
+ executables:
30
+ - easy_cache
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - README.md
35
+ - bin/easy_cache
36
+ - lib/easy_cache.rb
37
+ - lib/version.rb
38
+ homepage: http://github.com/maxpleaner/easy_cache
39
+ licenses:
40
+ - MIT
41
+ metadata: {}
42
+ post_install_message:
43
+ rdoc_options: []
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: 2.5.1
56
+ requirements: []
57
+ rubyforge_project:
58
+ rubygems_version: 2.5.1
59
+ signing_key:
60
+ specification_version: 4
61
+ summary: super easy way to cache results of a method (saves to yaml file)
62
+ test_files: []