cache_manager 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3f9a81d0be1d681986151fc6043e789095a970d6
4
- data.tar.gz: c2c3788801d4f0ea832bc723dd4ef8d7321935b1
3
+ metadata.gz: 451ca392db1b5c3a6106d4e110f6e955ca10b4c9
4
+ data.tar.gz: 1fbed941c63e5e13c6c638a60bbab208fc810b92
5
5
  SHA512:
6
- metadata.gz: 46eee55be12bc7406ead3b712647b8db0c3bd753984e8ce64c82141e3109f6ac42893827c06ca7dfe9b1f2890085a80bc9a145db5f587bbbd28591d92a99ebde
7
- data.tar.gz: be00db775a41e99b12de8d280aa5da716d46347ac2d219f2e5fb74d12bf7fc507fe2913be2038b91c72b66fb2c889851cf95cd9bc95298ed8716264073b15baa
6
+ metadata.gz: acfc8cdddf41c9f29c9c56d9df261895835d746b0c79f0b99c6097b760289517c380e9cbc7d44bc4b70943752efefadebac4390320ceb47c5a41a2275204fdb7
7
+ data.tar.gz: c79ea664a6bd8b074ceca5ae4bbf5ae8b8e04f03333753597668ab67ea3dfa0b51605d4b7f23f30c7f0fecea9c88c8194367a0474bc83c05eb3a5ca9b5047469
@@ -0,0 +1,50 @@
1
+ Cache Manager
2
+ -----
3
+
4
+ Mountable Rails engine to view your cache and manage the keys / cleanup cache.
5
+
6
+ **Note:** Currently tested with Filestore and Redis Cache store.
7
+
8
+ Installation
9
+ -----
10
+
11
+ Add the Gem in your Gemfile
12
+
13
+ ```ruby
14
+ gem 'cache_manager'
15
+ ```
16
+
17
+ And bundle
18
+ ```ruby
19
+ $ bundle install
20
+ ```
21
+
22
+ Once installed, Mount the engine to your routes.rb
23
+
24
+ ```ruby
25
+ # routes.rb
26
+
27
+ Rails.application.routes.draw do
28
+ # your other routes
29
+ # snipped for brevity
30
+ mount CacheManager::Engine => "/cache_manager"
31
+ end
32
+ ```
33
+
34
+ Usage
35
+ ------
36
+
37
+ Once it's mounted you can access it via browser
38
+
39
+ <a href='http://localhost:3000/cache_manager'>http://localhost:3000/cache_manager</a>
40
+
41
+ This brings you to the Landing page of cache manager. This Gives information about your Cache Stats
42
+
43
+ ![alt](http://s4.postimg.org/ql1kc1wm5/Screen_Shot_2015_08_11_at_11_23_11_AM.png)
44
+
45
+
46
+ <a href='http://localhost:3000/cache_manager/keys'>http://localhost:3000/cache_manager/keys</a>
47
+
48
+ This Brings you to the page which lists all your Keys and you can delete them . Clicking on individual links will take you to the page which displays the Cache information.
49
+
50
+ ![alt](http://s4.postimg.org/665jkcuhp/Screen_Shot_2015_08_11_at_11_23_42_AM.png)
File without changes
File without changes
@@ -9,5 +9,12 @@ module CacheManager
9
9
  def show
10
10
  @key = Key.find(params[:id])
11
11
  end
12
+
13
+ def flush
14
+ @key = Key.flush(params[:key])
15
+ respond_to do |format|
16
+ format.html { redirect_to keys_url, notice: 'Keys were successfully flushed.' }
17
+ end
18
+ end
12
19
  end
13
20
  end
@@ -1,15 +1,56 @@
1
1
  module CacheManager
2
2
  class Key
3
+ EXCLUDED_DIRS = ['.', '..', 'assets'].freeze
3
4
 
4
- #Rails.cache.instance_variable_get(:@data).keys
5
+ attr_reader :klass
6
+
7
+ def initialize
8
+ @klass = Rails.cache.class.to_s
9
+ end
10
+
11
+ # Rails.cache.instance_variable_get(:@data).keys
5
12
  class << self
6
13
  def all
7
- Rails.cache.instance_variable_get(:@data).keys
14
+ new.all
15
+ end
16
+
17
+ def flush(id)
18
+ if id == 'all'
19
+ Rails.cache.clear
20
+ else
21
+ Rails.cache.delete(id)
22
+ end
8
23
  end
9
24
 
10
25
  def find(id)
11
26
  Rails.cache.read(id)
12
27
  end
28
+
29
+ def destroy(id)
30
+ Rails.cache.delete(id)
31
+ end
32
+ end
33
+
34
+ def all
35
+ case @klass
36
+ when 'ActiveSupport::Cache::FileStore'
37
+ keys_for_file_store
38
+ else
39
+ keys_for_memory_store
40
+ end
41
+ end
42
+
43
+ def keys_for_memory_store
44
+ Rails.cache.instance_variable_get(:@data).keys
45
+ end
46
+
47
+ def keys_for_file_store
48
+ cache_path = Rails.cache.instance_variable_get(:'@cache_path')
49
+ root_dirs = Dir.entries(cache_path).reject { |f| (EXCLUDED_DIRS + ['.gitkeep']).include?(f) }
50
+ full_paths = root_dirs.collect { |i| cache_path + "#{i}" }
51
+ full_paths.collect do |dir|
52
+ File.basename(Dir["#{dir}/*/*"][0]) if Dir["#{dir}/*/*"][0]
53
+ end
13
54
  end
14
55
  end
15
56
  end
@@ -1,9 +1,22 @@
1
1
  module CacheManager
2
2
  class Stats
3
+ attr_reader :klass
4
+
5
+ def initialize
6
+ @klass = Rails.cache.class.to_s
7
+ end
3
8
 
4
- #Rails.cache.instance_variable_get(:@data).keys
5
9
  class << self
6
10
  def all
11
+ new.all
12
+ end
13
+ end
14
+
15
+ def all
16
+ case @klass
17
+ when 'ActiveSupport::Cache::FileStore'
18
+ {}
19
+ else
7
20
  Rails.cache.stats
8
21
  end
9
22
  end
@@ -1,4 +1,17 @@
1
- <h1> <%= @keys.count %> keys </h1>
1
+ <div class="row">
2
+ <div class="col-md-8">
3
+ <h1>
4
+ <%= pluralize(@keys.count, 'key') %>
5
+ </h1>
6
+ </div>
7
+ <div class="col-md-4">
8
+ <%= form_tag({controller: :keys, action: :flush}, method: "put") do %>
9
+ <%= hidden_field_tag :key, 'all' %>
10
+ <%= submit_tag "Flush All Keys" ,class: 'btn btn-block btn-danger' %>
11
+ <% end %>
12
+ </div>
13
+ </div>
14
+
2
15
  <table class="table">
3
16
  <thead>
4
17
  <th>
@@ -10,14 +23,18 @@
10
23
  </thead>
11
24
  <tbody>
12
25
  <% @keys.each do |key| %>
13
- <tr>
14
- <td>
15
- <%= link_to key, key_url(id: key) %>
16
- </td>
17
- <td>
18
- <%= link_to 'Delete', '#',class: 'btn btn-danger btn-xs' %>
19
- </td>
20
- </tr>
26
+ <tr>
27
+ <td>
28
+ <%= link_to key, key_url(id: key) %>
29
+ </td>
30
+ <td>
31
+ <%#= link_to 'Delete', '#',class: 'btn btn-danger btn-xs' %>
32
+ <%= form_tag({controller: :keys, action: :flush}, method: "put") do %>
33
+ <%= hidden_field_tag :key, key %>
34
+ <%= submit_tag "Flush" ,class: 'btn btn-danger btn-xs' %>
35
+ <% end %>
36
+ </td>
37
+ </tr>
21
38
  <% end %>
22
39
  </tbody>
23
40
  </table>
@@ -1,3 +1 @@
1
-
2
- <%= debug @key %>
3
-
1
+ <%= debug @key %>
@@ -1,3 +1,10 @@
1
+ <div class="jumbotron">
2
+ <h2>Environment: <%= Rails.env.humanize %></h2>
3
+ <h2>Cache Store: <%= Rails.cache.class %></h2>
4
+ </div>
5
+
6
+
7
+ <% if @stats.present? %>
1
8
  <table class="table">
2
9
  <thead>
3
10
  <tr>
@@ -7,14 +14,15 @@
7
14
  </thead>
8
15
  <tbody>
9
16
  <% @stats.each_pair do |key, value| %>
10
- <tr>
11
- <td>
12
- <%= key.humanize %>
13
- </td>
14
- <td>
15
- <%= value %>
16
- </td>
17
- </tr>
17
+ <tr>
18
+ <td>
19
+ <%= key.humanize %>
20
+ </td>
21
+ <td>
22
+ <%= value %>
23
+ </td>
24
+ </tr>
18
25
  <% end %>
19
26
  </tbody>
20
- </table>
27
+ </table>
28
+ <% end %>
@@ -12,8 +12,11 @@
12
12
  <%= render partial: 'shared/navbar' %>
13
13
  <div class="container">
14
14
  <div class="row">
15
+ <% if notice.present? %>
16
+ <div class="alert alert-success" role="alert"><%= notice %></div>
17
+ <% end %>
15
18
  <%= yield %>
16
19
  </div>
17
20
  </div>
18
21
  </body>
19
- </html>
22
+ </html>
@@ -1,7 +1,9 @@
1
1
  CacheManager::Engine.routes.draw do
2
2
 
3
3
  resources :stats, only: :index
4
- resources :keys, only: [:index, :show]
4
+ resources :keys, only: [:index, :show] do
5
+ put :flush, on: :collection
6
+ end
5
7
 
6
8
  root to: "stats#index"
7
9
  end
@@ -1,5 +1,19 @@
1
1
  module CacheManager
2
2
  class Engine < ::Rails::Engine
3
3
  isolate_namespace CacheManager
4
+
5
+ initializer :assets do |app|
6
+ Rails.application.config.assets.precompile += %w( cm.css )
7
+ Rails.application.config.assets.precompile += %w( cm.js )
8
+
9
+ # number of complex assets.
10
+ Rails.application.config.assets.debug = true
11
+ Rails.application.config.assets.raise_runtime_errors = true
12
+
13
+ # Asset digests allow you to set far-future HTTP expiration dates on all assets,
14
+ # yet still be able to expire them through the digest params.
15
+ Rails.application.config.assets.digest = true
16
+
17
+ end
4
18
  end
5
19
  end
@@ -1,3 +1,3 @@
1
1
  module CacheManager
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cache_manager
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ankit Gupta
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-11 00:00:00.000000000 Z
11
+ date: 2015-08-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -24,20 +24,6 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: 4.2.3
27
- - !ruby/object:Gem::Dependency
28
- name: sqlite3
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
27
  description: Cache manager helps in managing your cache and it's keys
42
28
  email:
43
29
  - ankit.gupta8898@gmail.com
@@ -47,8 +33,11 @@ extra_rdoc_files: []
47
33
  files:
48
34
  - MIT-LICENSE
49
35
  - Rakefile
36
+ - Readme.md
50
37
  - app/assets/javascripts/cache_manager/application.js
38
+ - app/assets/javascripts/cm.js
51
39
  - app/assets/stylesheets/cache_manager/application.css
40
+ - app/assets/stylesheets/cm.css
52
41
  - app/controllers/cache_manager/application_controller.rb
53
42
  - app/controllers/cache_manager/keys_controller.rb
54
43
  - app/controllers/cache_manager/stats_controller.rb