r_cache 0.1.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
+ SHA256:
3
+ metadata.gz: be2185c3d90bde0067fd12cc176839a37640dbb1760dc1fb4a380b445e40adb1
4
+ data.tar.gz: 25b030dbc53a04ee07e57abcd24248e08073ee8773d67abb13729a6f54123e0e
5
+ SHA512:
6
+ metadata.gz: 4a0d15894abdae2e78f3c920b343298f5307494d7282790008ae2215c61dd5bec553d0d2800e37115d95840db3a7f7e5577be7c29a19a0eafdfd9141962c501a
7
+ data.tar.gz: 971fc09b61c793eb6621cb4e1e25825a6def0e702717d6081de62b4d95f7d222735b93741df5d2ec2ddd17c7ec0f750d8738b1767c1ee483125b39cd9fc3645f
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem 'pry'
4
+ # Specify your gem's dependencies in r_cache.gemspec
5
+ gemspec
@@ -0,0 +1,28 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ r_cache (0.1.0)
5
+ redis
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ coderay (1.1.3)
11
+ method_source (1.0.0)
12
+ pry (0.13.1)
13
+ coderay (~> 1.1)
14
+ method_source (~> 1.0)
15
+ rake (10.5.0)
16
+ redis (4.1.4)
17
+
18
+ PLATFORMS
19
+ ruby
20
+
21
+ DEPENDENCIES
22
+ bundler (~> 2.0)
23
+ pry
24
+ r_cache!
25
+ rake (~> 10.0)
26
+
27
+ BUNDLED WITH
28
+ 2.0.2
@@ -0,0 +1,35 @@
1
+ # RCache
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/r_cache`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'r_cache'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install r_cache
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/r_cache.
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "r_cache"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,101 @@
1
+ require "r_cache/version"
2
+ require "redis"
3
+ require 'time'
4
+ require 'date'
5
+ #require 'pry'
6
+
7
+ module RCache
8
+ module Config
9
+ @@keys = {}
10
+
11
+ def self.keys
12
+ @@keys
13
+ end
14
+
15
+ def self.setKey key, val
16
+ @@keys[key] = val
17
+ end
18
+
19
+ def self.getKey key
20
+ @@keys[key]
21
+ end
22
+ end
23
+
24
+ class<<self
25
+ def config
26
+ Config
27
+ end
28
+ end
29
+
30
+
31
+ class Error < StandardError; end
32
+ # Your code goes here...
33
+
34
+ class Cache
35
+ @@redis = Redis.new
36
+
37
+ attr_accessor :updater
38
+
39
+ def expired? expiry # s
40
+ Time.now.to_i >= expiry.to_i
41
+ end
42
+
43
+ def store name, hash
44
+ add_expiry(hash) if Config.keys[:ttl]
45
+ @@redis.hmset name, *hash.to_a
46
+ end
47
+
48
+ def get name, keys=nil
49
+ unless keys
50
+ obj = @@redis.hgetall name
51
+ else
52
+ obj = @@redis.hmget name, *keys
53
+ end
54
+
55
+ puts 'about to update'
56
+ obj = update(name) if obj.nil? || ( Config.keys[:ttl] && expired?(obj['expiry']) )
57
+ # if nil or expired
58
+ # refresh
59
+ obj
60
+ end
61
+
62
+ def update name
63
+ puts 'updating'
64
+ delete [name]
65
+ n_obj = @updater.call(name)
66
+ store name, n_obj
67
+ #binding.pry
68
+ get name
69
+ end
70
+
71
+ def delete names
72
+ @@redis.del *names
73
+ end
74
+
75
+ private
76
+ def add_expiry hash
77
+ hash[:expiry] = Time.now.to_i + Config.keys[:ttl]
78
+ end
79
+ end
80
+ end
81
+
82
+ # RCache.config.setKey :ttl, 3
83
+
84
+ # @c = RCache::Cache.new
85
+ # obj = {"cond1"=>12, "cond2"=>37, "exchange"=>4, "price"=>352.89, "size"=>1, "timestamp"=>1591824674720}
86
+ # @c.updater = ->(name) {
87
+ # n_obj = {"cond1"=>12, "cond2"=>37, "exchange"=>4, "price"=>352.89, "size"=>1, "timestamp"=>1591824674720}
88
+ # n_obj
89
+ # }
90
+
91
+
92
+
93
+
94
+ # @r = @c.get 'obj'
95
+ # puts @c.expired? @r['expiry']
96
+ # sleep 3
97
+ # puts @c.expired? @r['expiry']
98
+ # @r = @c.get 'obj'
99
+ # puts @c.expired? @r['expiry']
100
+
101
+ # puts @r
@@ -0,0 +1,3 @@
1
+ module RCache
2
+ VERSION = "0.1.0.1"
3
+ end
@@ -0,0 +1,33 @@
1
+ lib = File.expand_path("lib", __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "r_cache/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "r_cache"
7
+ spec.version = RCache::VERSION
8
+ spec.authors = ["iodevel"]
9
+ spec.email = ["cbrandt92@gmail.com"]
10
+
11
+ spec.summary = %q{.}
12
+ # spec.description = %q{TODO: Write a longer description or delete this line.}
13
+ # spec.homepage = "TODO: Put your gem's website or public repo URL here."
14
+
15
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
16
+
17
+ # spec.metadata["homepage_uri"] = spec.homepage
18
+ # spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
19
+ # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
24
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ end
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_development_dependency "bundler", "~> 2.0"
31
+ spec.add_development_dependency "rake", "~> 10.0"
32
+ spec.add_runtime_dependency "redis"
33
+ end
data/todo ADDED
@@ -0,0 +1,2 @@
1
+ add undefined updater error
2
+ add verbose logging
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: r_cache
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - iodevel
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-06-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: redis
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description:
56
+ email:
57
+ - cbrandt92@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - Gemfile.lock
65
+ - README.md
66
+ - Rakefile
67
+ - bin/console
68
+ - bin/setup
69
+ - lib/r_cache.rb
70
+ - lib/r_cache/version.rb
71
+ - r_cache.gemspec
72
+ - todo
73
+ homepage:
74
+ licenses: []
75
+ metadata: {}
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubygems_version: 3.0.3
92
+ signing_key:
93
+ specification_version: 4
94
+ summary: "."
95
+ test_files: []