cache_cache 1.0.1 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +20 -0
  3. data/README.md +35 -0
  4. data/lib/cache_cache.rb +13 -7
  5. metadata +3 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: aa10894db3c207e37bca18a00f6d05d63f409997
4
- data.tar.gz: 7b69a4f470b3c1eec1d181c1f8e0997ee041416f
3
+ metadata.gz: 7046f0dea6b49b4ef2b68d12855cdcbdac5c1934
4
+ data.tar.gz: 9f9a961c1fc02e26ca730c557896c2f11bfb6db8
5
5
  SHA512:
6
- metadata.gz: 56d3e67595b1b4d0ce571a24dce0226c27db2a388d1323706315f2576f4ee0945988137dfc20ea4483dcf80df5c58595cadda7afbce39399074fef6a8415955c
7
- data.tar.gz: b81988453e5de261dff3abbf9d9b0b759da4ddfe30c1bcc247e17d7a5dd6ee64ac44b670a7452b1cd3729a1ab1aa7f8b8b5f24929dfbbc44e1ef76a70470d281
6
+ metadata.gz: d8ce0a2f855a00cead6307bfffa645ce4a0e826b4c992968c3187c0d279a91b95c1d15971a2c3245fb755cb270062fed62aed17b3528d88a7ca8b84d07ba5162
7
+ data.tar.gz: fe58ddc3d1bced7a4d3792a91a27f669aa400f9bf03baee60403b4180f426b81487ec3e846d586e34932fcc7425153129e984b2930491d1388346b5dd58a7c79
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2013 Oxyless
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ cache_cache
2
+ ===========
3
+
4
+ CacheCache allow you to manage dynamically multiple groups of HTML5 manifests using rails cache.
5
+
6
+ # Installation #
7
+
8
+ `> gem install cache_cache`
9
+
10
+ # Basic usage #
11
+
12
+ cache_cache = Rails::CacheCache.new(:group => :my_group) do
13
+ cache ActionController::Base.helpers.asset_path("application.css")
14
+ cache ActionController::Base.helpers.asset_path("application.js")
15
+ network "*"
16
+ save
17
+ end
18
+
19
+ print cache_cache.manifest
20
+
21
+ Display
22
+
23
+ CACHE MANIFEST
24
+ # generated by cache_cache
25
+ CACHE:
26
+ /assets/application.css
27
+ /assets/application.js
28
+ NETWORK:
29
+ *
30
+ FALLBACK:
31
+
32
+ # Hint #
33
+
34
+ Don't forget to active manifest in your rails configuration:
35
+ - `Mime::Type.register_alias "text/cache-manifest", :manifest` in an initializer should be suffisant.
data/lib/cache_cache.rb CHANGED
@@ -8,14 +8,14 @@ module Rails
8
8
  # Constructor
9
9
  #
10
10
  def initialize(options = {}, &block)
11
- @memory_store = options.fetch(:memory_store, ActiveSupport::Cache::MemoryStore.new)
11
+ @memory_store = options.fetch(:memory_store, (ActiveSupport::Cache::MemoryStore.new rescue nil))
12
12
  @group = options.fetch(:group, :default)
13
13
 
14
14
  @cache = { }
15
15
  @network = { }
16
16
  @fallback = { }
17
17
 
18
- self.configure(&block) if block_given?
18
+ self.configure(&block) if block_given? and not self.cached
19
19
  end
20
20
 
21
21
  # Configure
@@ -32,7 +32,7 @@ module Rails
32
32
  @cache[@group] << entry
33
33
  end
34
34
 
35
- @cache[@group]
35
+ @cache[@group].flatten
36
36
  end
37
37
 
38
38
  # Get / Set an entry into the network section of the manifest
@@ -43,7 +43,7 @@ module Rails
43
43
  @network[@group] << entry
44
44
  end
45
45
 
46
- @network[@group]
46
+ @network[@group].flatten
47
47
  end
48
48
 
49
49
  # Get / Set an entry into the fallback section of the manifest
@@ -54,19 +54,25 @@ module Rails
54
54
  @fallback[@group] << entry
55
55
  end
56
56
 
57
- @fallback[@group]
57
+ @fallback[@group].flatten
58
58
  end
59
59
 
60
60
  # Save the current manifest
61
61
  #
62
62
  def save
63
- @memory_store.write(self.label, self.manifest)
63
+ @memory_store.write(self.label, self.manifest) rescue nil
64
64
  end
65
65
 
66
66
  # Get the manifest
67
67
  #
68
68
  def manifest
69
- return (@memory_store.read(self.label) or self.generate)
69
+ return (self.cached or self.generate)
70
+ end
71
+
72
+ # Get the manifest from cache ifp
73
+ #
74
+ def cached
75
+ @memory_store.read(self.label) rescue nil
70
76
  end
71
77
 
72
78
  # Generate the manifest
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cache_cache
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Clement Bruchon
@@ -17,6 +17,8 @@ executables: []
17
17
  extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
+ - README.md
21
+ - LICENSE
20
22
  - lib/cache_cache.rb
21
23
  homepage: https://github.com/Oxyless/cache_cache
22
24
  licenses: