flagpole_sitta 0.5.9 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -1,11 +1,8 @@
1
1
  = FlagpoleSitta
2
2
 
3
3
  I had visions, I was in them,
4
-
5
4
  I was looking into the mirror
6
-
7
5
  To see a little bit clearer
8
-
9
6
  The rottenness and evil in me.
10
7
 
11
8
  ♫~♫~♫~♫~♫~♫~♫~♫~♫~♫~♫~♫~♫~♫~♫~♫~♫~♫~♫~♫~♫~♫~♫
@@ -14,27 +11,31 @@ The rottenness and evil in me.
14
11
 
15
12
  ===This gem should be considered in early beta and highly unstable. Do not use in a production app!
16
13
 
17
- This gem was inspired in part by the song Flagpole Sitta by Harvey Danger. So if you like the gem and are wanting to help out please either donate your time and submits some patches, or donate to the band who wrote the song. They put there last two albums out there all open source like, only asking that those that could donate after downloading. While your donating, if you choose to do so, don't be afraid to download there albums, its good stuff!
14
+ This gem was inspired in part by the song Flagpole Sitta by Harvey Danger. So if you like the gem and are wanting to help out please either donate your time and submit some patches, or donate to the band who wrote the song. They put there last two albums out there all open source like, only asking that those that could donate after downloading. While your donating, if you choose to do so, don't be afraid to download their albums, its good stuff!
18
15
 
19
16
  http://www.harveydanger.com/contribute.php
20
17
 
21
- Another note on a personal level, I have some learning disabilities that make it so I frequently make grammar mistake, and once and a while just drop random articles out of my sentences. All this only happens when writing. So if something doesn't make sense in the docs don't be afraid to point it out or submit a patch. Because to me it all looks right.....
18
+ My grammar ability's are fail. So if something doesn't make sense in the docs don't be afraid to point it out and/or submit a patch. Because to me it all looks right.....
22
19
 
23
- This gem has also only so far been tested with memcache using the Dalli adapter. File System caching and memory caching are not recommended.Redis/Memcache are defiantly suggested and strongly encouraged for this gem.
20
+ This gem has also only so far been tested with Memcache using the Dalli gem. File System caching and memory caching are not recommended.Redis/Memcache are defiantly suggested and strongly encouraged for this gem.
24
21
 
25
22
  == Installation
26
23
 
27
- For now add the following line to your gemfile
24
+ Very simple, in your gemfile
28
25
 
29
- gem 'flagpole_sitta', :git => "git://github.com/rovermicrover/FlagpoleSitta.git"
26
+ gem 'flagpole_sitta'
27
+
28
+ OR
29
+
30
+ gem 'flagpole_sitta', :git => "git://github.com/rovermicrover/FlagpoleSitta.git"
30
31
 
31
32
  Then bundle install.
32
33
 
33
- == About
34
+ == cache_sitta
34
35
 
35
- Flagpole Sitta is a gem that main purpose is to make it easier to effectively fragment cache in dynamic fashions in Rails.
36
+ Flagpole Sitta is a gem thats main purpose is to make it easier to effectively fragment cache in dynamic fashions in Rails.
36
37
 
37
- When ever a cache is created it is associated with any model and/or record you tell it to be from the view helper method. When that model and/or record is updated all it's associated cache's are cleared.
38
+ When ever a cache is created it is associated with any model and/or record you tell it to be from the view helper method. When that model and/or record is updated all it's associated caches are cleared.
38
39
 
39
40
  Flagpole also expects you to put all your database calls into Procs/Lamdbas. This makes it so that your database calls wont have to happen unless your cache hasn't been created. Thus speeding up response time and reducing database traffic.
40
41
 
@@ -42,23 +43,31 @@ For a simple application you could do something like this.
42
43
 
43
44
  === PageModel
44
45
 
45
- cache_sitta :route_id => "url"
46
+ class Page < ActiveRecord::Base
47
+
48
+ cache_sitta :route_id => "url"
49
+
50
+ end
46
51
 
47
52
  === PagesController
48
53
 
49
- def show
54
+ class PagesController < ApplicationController
50
55
 
51
- @page_call = lambda {
52
- if params[:url]
53
- @page = Page.find_by_url params[:url]
54
- else
55
- @page = Page.find_by_url 'home'
56
- end
57
- }
56
+ def show
58
57
 
59
- @body_calls = [
60
- ['page', @page_call]
61
- ]
58
+ @page_call = lambda {
59
+ if params[:url]
60
+ @page = Page.find_by_url params[:url]
61
+ else
62
+ @page = Page.find_by_url 'home'
63
+ end
64
+ }
65
+
66
+ @body_calls = [
67
+ ['page', @page_call]
68
+ ]
69
+
70
+ end
62
71
 
63
72
  end
64
73
 
@@ -67,7 +76,7 @@ For a simple application you could do something like this.
67
76
  - cache_sitta :model => Page, :route_id => params[:url], :section => "body" do
68
77
  = @page.content.try(:html_safe)
69
78
 
70
- First off lets look at @body_calls. The if you don't provide cache_sitta :calls, then it will look for @#{:section}_calls. So in this case it will look for @body_calls.
79
+ First off lets look at @body_calls. If you don't provide cache_sitta :calls, then it will look for @#{:section}_calls. So in this case it will look for @body_calls.
71
80
 
72
81
  Second off @body_calls is an array of arrays. This is because you can have multiple calls, and each call must be given a target instance variable ('page') and a call object (@page_call). So in this instance the cache_sitta helper will do
73
82
 
@@ -83,19 +92,27 @@ For an index page you could do something like the following for a simple app.
83
92
 
84
93
  === BlogModel
85
94
 
86
- cache_sitta :route_id => "url"
95
+ class Blog < ActiveRecord::Base
96
+
97
+ cache_sitta
98
+
99
+ end
87
100
 
88
101
  === BlogsController
89
102
 
90
- def index
103
+ class BlogsController < ApplicationController
104
+
105
+ def index
91
106
 
92
- @blogs_call = lambda {
93
- @blogs = Blog.all
94
- }
107
+ @blogs_call = lambda {
108
+ @blogs = Blog.all
109
+ }
95
110
 
96
- @body_calls = [
97
- ['blogs', @blogs_call]
98
- ]
111
+ @body_calls = [
112
+ ['blogs', @blogs_call]
113
+ ]
114
+
115
+ end
99
116
 
100
117
  end
101
118
 
@@ -107,12 +124,78 @@ For an index page you could do something like the following for a simple app.
107
124
  etc
108
125
  etc
109
126
 
110
- First notice you don't have to pass :route_id if you pass :index_only => true. And you don't have to pass :model if you pass :models_in_index.
127
+ First notice you don't have to pass :route_id and :model if you pass :index_only => true and :models_in_index.
128
+
129
+ This also means if your just showing objects in an index you don't even have to worry about declaring a route_id(It just defaults to id anyway.)
111
130
 
112
131
  :models_in_index tells the helper which Model to associated with the index, so if any objects in that model update the index cache gets nuked.
113
132
 
114
133
  :index_only => true, tells the helper to not bother trying to associated this cache with anyone item in particular.
115
134
 
135
+ == existence_hash
136
+
137
+ If you might have already figured out the overall strategy of this gem has a weakness. Namely how do you deal with instances where, the object being routed to doesn't exist. See if your not querying the database until your already in the view then you can't exactly redirect with out some crazy stuff going on. You could put some if statements in your view to show a 404 if the objects are nil, but the issue with that is that you would still end up with a bunch of pointless caches. This can all be avoided by creating a 'hash' in the cache which you can use to check for the existence of an object. This 'hash' too is updated on save/destory. Also the hash really isn't hash but rather a bunch of cache keys held together by a flag key. Lets use the page example from above.
138
+
139
+ === PageModel
140
+
141
+ class Page < ActiveRecord::Base
142
+
143
+ cache_sitta :route_id => "url"
144
+ has_existence_hash :route_id => "url"
145
+
146
+ end
147
+
148
+ A quick note you only actually have to pass :route_id once if your using both cache_sitta and has_existence_hash. It uses the same class instance variable.
149
+
150
+ === PagesController
151
+
152
+ class PagesController < ApplicationController
153
+
154
+ if Page.get_existence_hash(params[:url])
155
+
156
+ def show
157
+
158
+ @page_call = lambda {
159
+ if params[:url]
160
+ @page = Page.find_by_url params[:url]
161
+ else
162
+ @page = Page.find_by_url 'home'
163
+ end
164
+ }
165
+
166
+ @body_calls = [
167
+ ['page', @page_call]
168
+ ]
169
+
170
+ end
171
+
172
+ else
173
+ redirect_to :action => 'home'
174
+ flash[:notice] = "The Page you are looking for doesn't exist"
175
+ end
176
+
177
+ end
178
+
179
+ This will keep your cache safe from being filled with junk. Though this isn't the only way you can use the 'existence hash' to solve this problem. Another note is that the hash is created the first time that you call for it. If you have a enough objects this can take a while. So its suggest that you warm all 'existence hash'es just in case.
180
+
181
+ == has_brackets_retrieval
182
+
183
+ This is best used for settings or html fragments stored in the database. It will look for the object in cache, and then if not there query the database and then create the object in cache. These caches too gets cleared on save/destory of their related objects. If the object isn't in the database, it will create it for you with a default value of an empty string. You can pass it what ever value you want for a default with :default_value. Also it defaults to assuming the content isn't html safe. You can make it return as an html_safe buffer by passing it :safe_content? => true.
184
+
185
+ === Setting Model
186
+
187
+ class Setting < ActiveRecord::Base
188
+ has_brackets_retrieval :key => :name, :value => :content
189
+ end
190
+
191
+ Key is what you must pass to the brackets on the model. Value is the field it will return.
192
+
193
+ === View Example
194
+
195
+ %meta{:name => "description", :content => Setting['meta_description']}
196
+
197
+ This amounts to a very small specific cache_sitta call. For now its suggested to not use this feature for user generated content.
198
+
116
199
  == Footer
117
200
 
118
201
  More examples to come in the wiki, and in the coming example app.
@@ -9,8 +9,8 @@ Gem::Specification.new do |s|
9
9
  s.authors = ["Andrew Rove (Rover)"]
10
10
  s.email = ["rovermicrover@gmail.com"]
11
11
  s.homepage = "https://github.com/rovermicrover/FlagpoleSitta"
12
- s.summary = "FlagpoleSitta a gem for effective dynamic caching"
13
- s.description = "Flagpole Sitta is a gem that main purpose is to make it easier to effectively fragment cache in dynamic fashions.\n When ever a cache is created it is associated with any model and/or record you tell it to be from the helper method. When that model and/or record is updated all it's associated cache's are cleared.\n Flagpole also expects you to put all your database calls into Procs/Lamdbas. This makes it so that your database calls wont have to happen unless your cache hasn't been created. Thus speeding up response time and reducing database traffic."
12
+ s.summary = "FlagpoleSitta is a gem for effective dynamic caching"
13
+ s.description = "Flagpole Sitta is a gem that main purpose is to make it easier to effectively fragment cache in dynamic fashions in Rails. \nWhen ever a cache is created it is associated with any model and/or record you tell it to be from the view helper method. When that model and/or record is updated all it's associated caches are cleared. \nFlagpole also expects you to put all your database calls into Procs/Lamdbas. This makes it so that your database calls wont have to happen unless your cache hasn't been created. Thus speeding up response time and reducing database traffic."
14
14
 
15
15
  s.files = `git ls-files`.split("\n")
16
16
  s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
@@ -45,6 +45,7 @@ module FlagpoleSitta
45
45
  result = @_value_field || (self.superclass.respond_to?(:value_field) ? self.superclass.value_field : nil) || "content"
46
46
  end
47
47
 
48
+ #Will look up the object chain till it finds what it was set to, or not set too.
48
49
  def default_value
49
50
  result = @_default_value || (self.superclass.respond_to?(:default_value) ? self.superclass.default_value : nil) || ""
50
51
  end
@@ -9,9 +9,9 @@ module FlagpoleSitta
9
9
  @_route_id || (self.superclass.respond_to?(:route_id) ? self.superclass.route_id : nil) || "id"
10
10
  end
11
11
 
12
- def has_existance_hash options = {}
12
+ def has_existence_hash options = {}
13
13
  @_route_id ||= options[:route_id] ? options[:route_id].to_s : @_route_id
14
- include FlagpoleSitta::ExistanceHash
14
+ include FlagpoleSitta::ExistenceHash
15
15
  end
16
16
 
17
17
  def has_brackets_retrieval options = {}
@@ -1,39 +1,39 @@
1
1
  module FlagpoleSitta
2
- module ExistanceHash
2
+ module ExistenceHash
3
3
 
4
4
  extend ActiveSupport::Concern
5
5
 
6
6
  included do
7
- before_save :existance_hash_save_update
8
- before_destroy :existance_hash_destory_update
7
+ before_save :existence_hash_save_update
8
+ before_destroy :existence_hash_destory_update
9
9
  end
10
10
 
11
11
  module ClassMethods
12
12
 
13
- def get_existance_hash key
13
+ def get_existence_hash key
14
14
 
15
- dcname = get_super_with_existance_hash.name.downcase
15
+ dcname = get_super_with_existence_hash.name.downcase
16
16
  #Try to find the hash
17
- flag = Rails.cache.read("#{dcname}_existance_hash_flag")
17
+ flag = Rails.cache.read("#{dcname}_existence_hash_flag")
18
18
  #If it doesn't exist start the process of creating it
19
19
  if flag.nil?
20
- initialize_existance_hash
20
+ initialize_existence_hash
21
21
  end
22
22
 
23
- Rails.cache.read("#{dcname}_existance_hash/#{key}")
23
+ Rails.cache.read("#{dcname}_existence_hash/#{key}")
24
24
 
25
25
  end
26
26
 
27
- def increment_existance_hash key
27
+ def increment_existence_hash key
28
28
 
29
- dcname = get_super_with_existance_hash.name.downcase
29
+ dcname = get_super_with_existence_hash.name.downcase
30
30
  #Try to find the hash
31
- hash = get_existance_hash key
31
+ hash = get_existence_hash key
32
32
 
33
33
  #Update the hash key if it exists
34
34
  if hash
35
35
  hash[:num] = hash[:num] + 1
36
- Rails.cache.write("#{dcname}_existance_hash/#{key}", hash)
36
+ Rails.cache.write("#{dcname}_existence_hash/#{key}", hash)
37
37
  end
38
38
 
39
39
  #Return the value
@@ -41,28 +41,28 @@ module FlagpoleSitta
41
41
 
42
42
  end
43
43
 
44
- def get_super_with_existance_hash
44
+ def get_super_with_existence_hash
45
45
 
46
- if @_existance_hash_main_class.nil?
46
+ if @_existence_hash_main_class.nil?
47
47
 
48
48
  c = self
49
49
  #Get the original super class that declares the existence hash
50
50
 
51
- while(c.superclass.respond_to? :get_existance_hash)
51
+ while(c.superclass.respond_to? :get_existence_hash)
52
52
  c = c.superclass
53
53
  end
54
54
 
55
- @_existance_hash_main_class = c
55
+ @_existence_hash_main_class = c
56
56
 
57
57
  end
58
58
 
59
- @_existance_hash_main_class
59
+ @_existence_hash_main_class
60
60
 
61
61
  end
62
62
 
63
- def initialize_existance_hash
63
+ def initialize_existence_hash
64
64
 
65
- c = get_super_with_existance_hash
65
+ c = get_super_with_existence_hash
66
66
 
67
67
  dcname = c.name.downcase
68
68
 
@@ -72,12 +72,12 @@ module FlagpoleSitta
72
72
 
73
73
  flag = {:space => (count - 1), :count => count}
74
74
 
75
- Rails.cache.write("#{dcname}_existance_hash_flag", flag)
75
+ Rails.cache.write("#{dcname}_existence_hash_flag", flag)
76
76
  i = 0
77
77
  c.find_each do |m|
78
78
  #Route ID is the key. The POS is used to emulate an array, along with the length stored in the flag.
79
- Rails.cache.write("#{dcname}_existance_hash/#{m.send(c.route_id).to_s}", {:type => m.has_attribute?('type') ? m.type : m.class, :pos => i, :num => 0})
80
- Rails.cache.write("#{dcname}_existance_hash/#{i}", {:key => m.send(c.route_id).to_s})
79
+ Rails.cache.write("#{dcname}_existence_hash/#{m.send(c.route_id).to_s}", {:type => m.has_attribute?('type') ? m.type : m.class, :pos => i, :num => 0})
80
+ Rails.cache.write("#{dcname}_existence_hash/#{i}", {:key => m.send(c.route_id).to_s})
81
81
  i = i + 1
82
82
  end
83
83
 
@@ -85,23 +85,23 @@ module FlagpoleSitta
85
85
 
86
86
  end
87
87
 
88
- def each_existance_hash &block
88
+ def each_existence_hash &block
89
89
 
90
- dcname = get_super_with_existance_hash.name.downcase
90
+ dcname = get_super_with_existence_hash.name.downcase
91
91
 
92
- flag = Rails.cache.read("#{dcname}_existance_hash_flag")
92
+ flag = Rails.cache.read("#{dcname}_existence_hash_flag")
93
93
 
94
94
  if flag.nil?
95
- flag = initialize_existance_hash
95
+ flag = initialize_existence_hash
96
96
  end
97
97
 
98
98
  unless flag[:count] == 0
99
99
  for i in 0..flag[:space] do
100
100
 
101
- value = Rails.cache.read("#{dcname}_existance_hash/#{i}")
101
+ value = Rails.cache.read("#{dcname}_existence_hash/#{i}")
102
102
 
103
103
  if value.present?
104
- hash = Rails.cache.read("#{dcname}_existance_hash/#{value[:key]}")
104
+ hash = Rails.cache.read("#{dcname}_existence_hash/#{value[:key]}")
105
105
  yield value[:key], hash
106
106
  end
107
107
 
@@ -114,30 +114,30 @@ module FlagpoleSitta
114
114
 
115
115
  end
116
116
 
117
- def existance_hash_save_update
118
- self.update_existance_hash(true)
117
+ def existence_hash_save_update
118
+ self.update_existence_hash(true)
119
119
  end
120
120
 
121
- def existance_hash_destory_update
122
- self.update_existance_hash(false)
121
+ def existence_hash_destory_update
122
+ self.update_existence_hash(false)
123
123
  end
124
124
 
125
- def update_existance_hash alive
126
- c = self.class.get_super_with_existance_hash
125
+ def update_existence_hash alive
126
+ c = self.class.get_super_with_existence_hash
127
127
  dcname = c.name.downcase
128
128
 
129
129
  #Old key is where it was, and new is where it is going.
130
130
  old_key = self.send("#{self.class.route_id}_was")
131
131
  new_key = self.send("#{self.class.route_id}")
132
132
 
133
- flag = Rails.cache.read("#{dcname}_existance_hash_flag")
133
+ flag = Rails.cache.read("#{dcname}_existence_hash_flag")
134
134
 
135
135
  #If it had a route_id before it most of existed. So get its old values from the existence hash.
136
136
  #If there was nothing it didn't exist so create a new one. Also it only creates a new one if alive is set to true.
137
137
  #This check is overkill really, but its just to be safe.
138
138
  if old_key
139
- hash = self.class.get_existance_hash(self.send("#{self.class.route_id}_was"))
140
- Rails.cache.delete("#{dcname}_existance_hash/#{old_key}")
139
+ hash = self.class.get_existence_hash(self.send("#{self.class.route_id}_was"))
140
+ Rails.cache.delete("#{dcname}_existence_hash/#{old_key}")
141
141
  elsif alive
142
142
  flag[:count] = flag[:count] + 1
143
143
  flag[:space] = flag[:space] + 1
@@ -146,17 +146,17 @@ module FlagpoleSitta
146
146
 
147
147
  #If the record is not being destroyed add new route_id to existence hash
148
148
  if alive
149
- Rails.cache.write("#{dcname}_existance_hash/#{new_key}", hash)
150
- Rails.cache.write("#{dcname}_existance_hash/#{hash[:pos]}", {:key => new_key})
149
+ Rails.cache.write("#{dcname}_existence_hash/#{new_key}", hash)
150
+ Rails.cache.write("#{dcname}_existence_hash/#{hash[:pos]}", {:key => new_key})
151
151
  else
152
152
  if hash[:pos] == flag[:space]
153
153
  flag[:space] = flag[:space] - 1
154
154
  end
155
155
  flag[:count] = flag[:count] - 1
156
- Rails.cache.delete("#{dcname}_existance_hash/#{hash[:pos]}")
156
+ Rails.cache.delete("#{dcname}_existence_hash/#{hash[:pos]}")
157
157
  end
158
158
 
159
- Rails.cache.write("#{dcname}_existance_hash_flag", flag)
159
+ Rails.cache.write("#{dcname}_existence_hash_flag", flag)
160
160
 
161
161
  end
162
162
 
@@ -1,3 +1,3 @@
1
1
  module FlagpoleSitta
2
- VERSION = "0.5.9"
2
+ VERSION = "0.6.0"
3
3
  end
@@ -13,7 +13,7 @@ end
13
13
 
14
14
  require 'flagpole_sitta/bracket_retrieval'
15
15
  require 'flagpole_sitta/cache_sitta'
16
- require 'flagpole_sitta/existance_hash'
16
+ require 'flagpole_sitta/existence_hash'
17
17
  require 'flagpole_sitta/engine'
18
18
  require 'flagpole_sitta/config_sitta'
19
19
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flagpole_sitta
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.9
4
+ version: 0.6.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-18 00:00:00.000000000 Z
12
+ date: 2012-07-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: dalli
@@ -28,12 +28,13 @@ dependencies:
28
28
  - !ruby/object:Gem::Version
29
29
  version: '0'
30
30
  description: ! "Flagpole Sitta is a gem that main purpose is to make it easier to
31
- effectively fragment cache in dynamic fashions.\n When ever a cache is created it
32
- is associated with any model and/or record you tell it to be from the helper method.
33
- When that model and/or record is updated all it's associated cache's are cleared.\n
34
- Flagpole also expects you to put all your database calls into Procs/Lamdbas. This
35
- makes it so that your database calls wont have to happen unless your cache hasn't
36
- been created. Thus speeding up response time and reducing database traffic."
31
+ effectively fragment cache in dynamic fashions in Rails. \nWhen ever a cache is
32
+ created it is associated with any model and/or record you tell it to be from the
33
+ view helper method. When that model and/or record is updated all it's associated
34
+ caches are cleared. \nFlagpole also expects you to put all your database calls into
35
+ Procs/Lamdbas. This makes it so that your database calls wont have to happen unless
36
+ your cache hasn't been created. Thus speeding up response time and reducing database
37
+ traffic."
37
38
  email:
38
39
  - rovermicrover@gmail.com
39
40
  executables: []
@@ -53,7 +54,7 @@ files:
53
54
  - lib/flagpole_sitta/cache_sitta.rb
54
55
  - lib/flagpole_sitta/config_sitta.rb
55
56
  - lib/flagpole_sitta/engine.rb
56
- - lib/flagpole_sitta/existance_hash.rb
57
+ - lib/flagpole_sitta/existence_hash.rb
57
58
  - lib/flagpole_sitta/version.rb
58
59
  - test/dummy/Rakefile
59
60
  - test/dummy/app/controllers/application_controller.rb
@@ -113,5 +114,5 @@ rubyforge_project:
113
114
  rubygems_version: 1.8.24
114
115
  signing_key:
115
116
  specification_version: 3
116
- summary: FlagpoleSitta a gem for effective dynamic caching
117
+ summary: FlagpoleSitta is a gem for effective dynamic caching
117
118
  test_files: []