firebolt 0.9.0 → 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Firebolt
2
2
 
3
- Firebolt is a simple cache warmer. It warms the cache using a specially defined warmer class. It also has an optional file-based warmer.
3
+ Firebolt is a simple cache warmer. It warms the cache using a specially defined warmer class. It also has an optional file-based warmer to make boot-time fast!
4
4
 
5
5
  It's not quite ready for Prime Time™ and needs specs (YIKES!). Feel free add some, if you like...
6
6
 
@@ -20,16 +20,50 @@ Or install it yourself as:
20
20
 
21
21
  ## Usage
22
22
 
23
- To use Firebolt, you first need to configure it:
23
+ To use Firebolt, you first need to configure it.
24
+
25
+ #### Configure & Initialize!
26
+
27
+ ```Ruby
28
+ ::Firebolt.configure do |config|
29
+ # Required
30
+ config.cache = ::Rails.cache # Or anything that adheres to Rails's cache interface
31
+ config.warming_frequency = 12.hours # In seconds. Get minutes/hours/days helper w/ ActiveSupport
32
+ config.warmer = ::YourAwesomeCacheWarmer
33
+
34
+ # Optional
35
+ config.cache_file_enabled = true # Automatically enabled when cache_file_path is set
36
+ config.cache_file_path = '/path/to/your/project/tmp' # Defaults to /tmp
37
+ end
38
+ ```
39
+
40
+ Then you need to initialize it:
24
41
 
25
42
  ```Ruby
26
- ::Firebolt.initialize! do |firebolt_config|
27
- firebolt_config.cache = ::Rails.cache
28
- firebolt_config.frequency = 12.hours
29
- firebolt_config.warmer = ::YourAwesomeCacheWarmer
43
+ # Calling initialize! starts the warming cycle.
44
+ # It's best to skip the warming cycle while running specs. Warming is
45
+ # automatically skipped while running specs in Rails apps. In other apps, set
46
+ # FIREBOLT_SKIP_WARMING to true (or 1, or 'sandwich').
47
+ ::Firebolt.initialize!
48
+
49
+ # Also takes a block so you can initialize and configure at the same time:
50
+ ::Firebolt.initialize! do |config|
51
+ config.cache = ::Rails.cache
52
+ config.warming_frequency = 12.hours
53
+ config.warmer = ::YourAwesomeCacheWarmer
30
54
  end
31
55
  ```
32
56
 
57
+ #### Reading cached data
58
+
59
+ Firebolt provides two methods for retrieving cached data: `Firebolt.read` & `Firebolt.fetch`.
60
+
61
+ `Firebolt.read` takes your cache key and return the value from the cache.
62
+
63
+ `Firebolt.fetch` does the same thing, but also takes an optional block that is called when there is a cache miss.
64
+
65
+ #### Warming the cache
66
+
33
67
  Firebolt uses a cache warmer that you create. Valid cache warmers must:
34
68
 
35
69
  1. Include `Firebolt::Warmer`
@@ -47,7 +81,15 @@ class YourAwesomeCacheWarmer
47
81
  end
48
82
  ```
49
83
 
50
- More documentation coming soon...
84
+ Firebolt uses this warmer to re-warm the cache at the frequency you configure (e.g. `config.warming_frequency`). If it's set to re-warm every 12 hours, Firebolt will warm the cache every twelve hours.
85
+
86
+ Under the hood, Firebolt keeps track of the current cache set. That way, it's able to warm a new cache set and swap it with the old cache set in place, avoiding cache misses.
87
+
88
+ #### The file warmer
89
+
90
+ Firebolt is built to be fast and unobtrusive, but sometimes warming a cache can take some time. That's where the file warmer comes in. When the file warmer is enabled, after warming the cache, Firebolt will write the cached data to a file. The next time your app starts up, it will warm the cache from the file. Each subsequent warming happens with your custom warmer.
91
+
92
+ To use file warmer, simply set the `cache_file_enabled` and `cache_file_path` config options.
51
93
 
52
94
  ## Contributing
53
95
 
@@ -0,0 +1,23 @@
1
+ module Firebolt
2
+ class Railtie < Rails::Railtie
3
+ initializer "firebolt.rails.configuration" do |app|
4
+ # Configure Firebolt
5
+ ::Firebolt.configure do |config|
6
+ app.config.firebolt.each do |config_key, config_value|
7
+ config_setter = "#{config_key}="
8
+ config.__send__(config_setter, config_value) if config.respond_to?(config_setter)
9
+ end
10
+
11
+ # Set defaults based on Rails
12
+ config.cache ||= ::Rails.cache
13
+ config.cache_file_path ||= ::File.join(::Rails.root, 'tmp')
14
+ end
15
+ end
16
+
17
+ # Load Firebolt Rake tasks
18
+ rake_tasks do
19
+ # load 'firebolt/tasks/cache.rake'
20
+ load ::File.join('firebolt', 'tasks', 'cache.rake')
21
+ end
22
+ end
23
+ end
@@ -1,3 +1,3 @@
1
1
  module Firebolt
2
- VERSION = "0.9.0"
2
+ VERSION = "0.9.1"
3
3
  end
data/lib/firebolt.rb CHANGED
@@ -9,9 +9,10 @@ require "firebolt/cache_worker"
9
9
  require "firebolt/config"
10
10
  require "firebolt/warmer"
11
11
  require "firebolt/file_warmer"
12
-
13
12
  require "firebolt/version"
14
13
 
14
+ require "firebolt/railtie" if defined?(::Rails::Railtie)
15
+
15
16
  module Firebolt
16
17
  extend ::Firebolt::Cache
17
18
 
@@ -41,9 +42,11 @@ module Firebolt
41
42
  end
42
43
 
43
44
  def self.initialize_rufus_scheduler
44
- frequency = ::Rufus.to_time_string(config.warming_frequency)
45
+ return if config.warming_frequency.nil?
46
+
47
+ warming_frequency = ::Rufus.to_time_string(config.warming_frequency)
45
48
 
46
- ::Rufus::Scheduler.start_new.every(frequency) do
49
+ ::Rufus::Scheduler.start_new.every(warming_frequency) do
47
50
  ::SuckerPunch::Queue[:firebolt_queue].async.perform(config.warmer)
48
51
  end
49
52
  end
@@ -55,7 +58,6 @@ module Firebolt
55
58
 
56
59
  raise "Firebolt.config.cache has not been set" unless config.cache
57
60
  raise "Firebolt.config.warmer has not been set" unless config.warmer
58
- raise "Firebolt.config.warming_frequency has not been set" unless config.warming_frequency
59
61
 
60
62
  configure_sucker_punch
61
63
  initialize_rufus_scheduler
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: firebolt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.9.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -96,6 +96,7 @@ files:
96
96
  - lib/firebolt/config.rb
97
97
  - lib/firebolt/file_warmer.rb
98
98
  - lib/firebolt/keys.rb
99
+ - lib/firebolt/railtie.rb
99
100
  - lib/firebolt/tasks/cache.rake
100
101
  - lib/firebolt/version.rb
101
102
  - lib/firebolt/warmer.rb
@@ -114,7 +115,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
114
115
  version: '0'
115
116
  segments:
116
117
  - 0
117
- hash: -3262743682020511243
118
+ hash: 553194532783204057
118
119
  required_rubygems_version: !ruby/object:Gem::Requirement
119
120
  none: false
120
121
  requirements:
@@ -123,10 +124,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
123
124
  version: '0'
124
125
  segments:
125
126
  - 0
126
- hash: -3262743682020511243
127
+ hash: 553194532783204057
127
128
  requirements: []
128
129
  rubyforge_project:
129
- rubygems_version: 1.8.24
130
+ rubygems_version: 1.8.25
130
131
  signing_key:
131
132
  specification_version: 3
132
133
  summary: Firebolt is a simple cache warmer. It warms the cache using a specially defined