rack-cache-tags 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,26 @@
1
+ require 'active_record'
2
+
3
+ module Rack
4
+ module Cache
5
+ class Tags
6
+ module Store
7
+ class ActiveRecord
8
+ class Tagging < ::ActiveRecord::Base
9
+ set_table_name 'cache_taggings'
10
+ end
11
+
12
+ def store(url, tags)
13
+ tags.each { |tag| Tagging.find_or_create_by_url_and_tag(url, tag) }
14
+ end
15
+
16
+ def purge(tags)
17
+ tags = Tagging.where(:tag => tags)
18
+ urls = tags.map(&:url)
19
+ Tagging.where(:url => urls).delete_all
20
+ urls
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,9 @@
1
+ module Rack
2
+ module Cache
3
+ class Tags
4
+ module Store
5
+ autoload :ActiveRecord, 'rack/cache/tags/store/active_record'
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,50 @@
1
+ require 'rack/request'
2
+
3
+ module Rack
4
+ module Cache
5
+ class Tags
6
+ autoload :Store, 'rack/cache/tags/store'
7
+
8
+ class << self
9
+ def store
10
+ @store ||= Store::ActiveRecord.new
11
+ end
12
+
13
+ def store=(store)
14
+ @store ||= store
15
+ end
16
+ end
17
+
18
+ TAGS_HEADER = 'rack-cache.tags'
19
+ PURGE_HEADER = 'rack-cache.purge'
20
+ PURGE_TAGS_HEADER = 'rack-cache.purge-tags'
21
+
22
+ attr_reader :app
23
+
24
+ def initialize(app)
25
+ @app = app
26
+ end
27
+
28
+ def call(env)
29
+ status, headers, body = app.call(env)
30
+ if status == 200
31
+ store(Rack::Request.new(env).url, headers[TAGS_HEADER]) if headers.key?(TAGS_HEADER)
32
+ purge(headers) if headers.key?(PURGE_TAGS_HEADER)
33
+ end
34
+ [status, headers, body]
35
+ end
36
+
37
+ protected
38
+
39
+ def store(*args)
40
+ self.class.store.store(*args)
41
+ end
42
+
43
+ def purge(headers)
44
+ urls = self.class.store.purge(headers[PURGE_TAGS_HEADER])
45
+ headers[PURGE_HEADER] = urls unless urls.empty?
46
+ headers.delete(PURGE_TAGS_HEADER)
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,3 @@
1
+ module RackCacheTags
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1 @@
1
+ require 'rack/cache/tags'
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rack-cache-tags
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Sven Fuchs
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-09-04 00:00:00 +02:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: "[description]"
23
+ email: svenfuchs@artweb-design.de
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - lib/rack/cache/tags/store/active_record.rb
32
+ - lib/rack/cache/tags/store.rb
33
+ - lib/rack/cache/tags.rb
34
+ - lib/rack_cache_tags/version.rb
35
+ - lib/rack_cache_tags.rb
36
+ has_rdoc: true
37
+ homepage: http://github.com/svenfuchs/rack-cache-tags
38
+ licenses: []
39
+
40
+ post_install_message:
41
+ rdoc_options: []
42
+
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ none: false
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ hash: 3
51
+ segments:
52
+ - 0
53
+ version: "0"
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ hash: 23
60
+ segments:
61
+ - 1
62
+ - 3
63
+ - 6
64
+ version: 1.3.6
65
+ requirements: []
66
+
67
+ rubyforge_project: "[none]"
68
+ rubygems_version: 1.3.7
69
+ signing_key:
70
+ specification_version: 3
71
+ summary: "[summary]"
72
+ test_files: []
73
+