webs 0.1.36 → 0.1.37

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -3,7 +3,7 @@ require 'rubygems'
3
3
  require 'rake'
4
4
  require 'echoe'
5
5
 
6
- Echoe.new('webs', '0.1.36') do |p|
6
+ Echoe.new('webs', '0.1.37') do |p|
7
7
  p.description = "Reusable webs stuff."
8
8
  p.url = "https://colczak@github.com/websdev/websgem.git"
9
9
  p.author = "Chuck Olczak"
data/lib/cache/cache.rb CHANGED
@@ -5,8 +5,8 @@ module Webs
5
5
  mattr_accessor :off
6
6
 
7
7
  def cache_remove(key)
8
- Rails.logger.debug "*********** cache_remove(#{key})" if debug
9
- return if key.nil?
8
+ Rails.logger.debug "*********** cache_remove( #{key} )" if debug
9
+ return if key.nil? || off
10
10
  Webs.cache.delete(key.to_s)
11
11
  rescue Exception => e
12
12
  Rails.logger.error "------------------------------------------------\nmemcache_error: #{e.message}"
@@ -14,56 +14,67 @@ module Webs
14
14
  end
15
15
 
16
16
  def cache_read( key )
17
- Rails.logger.debug "*********** cache_read(#{key})" if debug
18
- if Webs.cache.respond_to?( 'read' )
19
- Webs.cache.read(key)
20
- else
21
- Webs.cache[ key ]
22
- end
17
+ return nil if off
18
+ data = Webs.cache.respond_to?( 'read' ) ? Webs.cache.read(key.to_s) : Webs.cache[ key.to_s ]
19
+ Rails.logger.debug "****#{data ? 'HIT*' : 'MISS'}*** cache_read( #{key} )" if debug
20
+ data
23
21
  rescue Exception => e
24
22
  Rails.logger.error "------------------------------------------------\nmemcache_error: #{e.message}, #{e.backtrace.join("\n")}"
25
23
  nil
26
24
  end
27
-
28
- def cache_block(key, options=nil, &block)
29
- return if key.nil?
30
- if off
31
- if self.respond_to?('capture')
32
- data = capture(&block) # called from view
25
+
26
+ def cache_write( key, data, options={} )
27
+ s_data = Marshal.dump(data)
28
+ block_size = s_data.size
29
+ #TODO: Compression?
30
+ if block_size < 1.megabyte
31
+ Rails.logger.debug "*********** cache_write[#{block_size}]( #{key}, #{data && data.inspect.length > 100 ? data.inspect[0..100] : data} )" if debug
32
+ if Webs.cache.respond_to?( 'write' )
33
+ Webs.cache.write(key.to_s, data)
33
34
  else
34
- data = yield
35
+ Webs.cache[ key.to_s ] = data
35
36
  end
36
- Rails.logger.debug "****OFF**** cache_block(#{key})" if debug
37
- return data
37
+ else
38
+ Rails.logger.debug "*********** cache_write( #{key} ) not cached since exceeds 1M @ #{block_size} )" if debug
38
39
  end
39
-
40
+ rescue Exception => e
41
+ Rails.logger.error "------------------------------------------------\nmemcache_error: #{e.message}, #{e.backtrace.join("\n")}"
42
+ nil
43
+ end
44
+
45
+ def get_data( &block )
46
+ self.respond_to?('capture') ? capture(&block) : yield
47
+ end
48
+
49
+ def cache_block(key, options={}, &block)
50
+ return if key.nil?
51
+ Rails.logger.debug "*********** cache_block( #{key} )" if debug
52
+ return get_data( &block ) if off
53
+
40
54
  unless ( data=cache_read(key) )
41
- if self.respond_to?('capture')
42
- data = capture(&block) # called from view
43
- else
44
- data = yield
45
- end
46
- s_data = Marshal.dump(data)
47
- block_size = s_data.size
48
- #TODO: Check to see if dalli cache & compressed then up the size to 3MB
49
- # should get almost 10:1 compression ratio. This will be key for caching pages & fragments
50
- if block_size < 1.megabyte
51
- Rails.logger.debug "*********** cache_block[#{block_size}](#{key}, #{data && data.inspect.length > 100 ? data.inspect[0..100] : data} )" if debug
52
- if Webs.cache.respond_to?( 'write' )
53
- Webs.cache.write(key, data)
54
- else
55
- Webs.cache[ key ] = data
56
- end
57
- else
58
- Rails.logger.debug "*********** cache_block(#{key}) not cached since exceeds 3M @ #{block_size} )" if debug
59
- end
60
- else
61
- Rails.logger.debug "****HIT**** cache_block(#{key} )" if debug && !off
55
+ # if self responds to capture this is called from a view which means we can cache snippets
56
+ data = get_data( &block )
57
+ cache_write( key.to_s, data, options )
62
58
  end
63
59
  data
64
60
  rescue Exception => e
65
61
  Rails.logger.error "------------------------------------------------\nmemcache_error: #{e.message}, #{e.backtrace.join("\n")}"
66
62
  data
67
63
  end
64
+
65
+
66
+ # caching snippets works very similiarly to caching a block except that snippets have already
67
+ # been read to check for existence so we don't want to do a re-read. So generally in the controller
68
+ # you will do a cache_read on the key, setting a snippet @var, not do normal processing, then in view
69
+ # do a cache_snippet which checks to see if snippet param is set if not it will cache_block the snippet
70
+ # view otherwide just render the passed snippet
71
+ def cache_snippet(snippet, key, options={}, &block)
72
+ return snippet.html_safe if !snippet.blank?
73
+ if options.delete(:ignore_cache)
74
+ get_data( &block )
75
+ else
76
+ cache_block( key, options, &block )
77
+ end
78
+ end
68
79
  end
69
80
  end
@@ -144,7 +144,10 @@ module Webs
144
144
 
145
145
  # Usefull for debugging, set FW_PARAMS in development.rb and you can see the raw html in a browser
146
146
  def set_fw_params
147
- params.merge!( FW_PARAMS ) if defined?( FW_PARAMS )
147
+ if defined?( FW_PARAMS )
148
+ params.merge!( FW_PARAMS )
149
+ Rails.logger.debug "************ set_fw_params PARAMS=#{params.inspect}"
150
+ end
148
151
  end
149
152
 
150
153
  # NOTE: bots & perl scripts are getting bad format in the request headers
data/lib/webs.rb CHANGED
@@ -7,7 +7,7 @@ require dir + 'helper/params'
7
7
  require dir + 'helper/tags'
8
8
 
9
9
  module Webs
10
- VERSION = '0.1.36'.freeze
10
+ VERSION = '0.1.37'.freeze
11
11
 
12
12
  def self.app_title
13
13
  APP_NAME.titleize
data/webs.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{webs}
5
- s.version = "0.1.36"
5
+ s.version = "0.1.37"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Chuck Olczak"]
9
- s.date = %q{2011-05-09}
9
+ s.date = %q{2011-06-01}
10
10
  s.description = %q{Reusable webs stuff.}
11
11
  s.email = %q{chuck@webs.com}
12
12
  gemfiles = [
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: webs
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.36
5
+ version: 0.1.37
6
6
  platform: ruby
7
7
  authors:
8
8
  - Chuck Olczak
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-05-09 00:00:00 -04:00
13
+ date: 2011-06-01 00:00:00 -04:00
14
14
  default_executable:
15
15
  dependencies: []
16
16