rack-cache-purge 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,20 @@
1
+ module Rack
2
+ module Cache
3
+ class Purge
4
+ class << self
5
+ def allow_http_purge!
6
+ include Rack::Cache::Purge::Http
7
+ end
8
+ end
9
+
10
+ PURGE_HEADER = 'rack-cache.purge'
11
+ PURGER_HEADER = 'rack-cache.purger'
12
+
13
+ autoload :Base, 'rack/cache/purge/base'
14
+ autoload :Http, 'rack/cache/purge/http'
15
+ autoload :Purger, 'rack/cache/purge/purger'
16
+
17
+ include Base
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,21 @@
1
+ module Rack
2
+ module Cache
3
+ class Purge
4
+ module Base
5
+ attr_reader :app, :purger
6
+
7
+ def initialize(app, options = {})
8
+ self.class.allow_http_purge! if options[:allow_http_purge]
9
+ @app = app
10
+ end
11
+
12
+ def call(env)
13
+ purger = Purger.new(env)
14
+ status, headers, body = app.call(env.merge(PURGER_HEADER => purger))
15
+ purger.purge(headers.delete(PURGE_HEADER)) if headers.key?(PURGE_HEADER)
16
+ [status, headers, body]
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,22 @@
1
+ module Rack
2
+ module Cache
3
+ class Purge
4
+ module Http
5
+ def call(env)
6
+ http_purge?(env) ? http_purge(env) : super
7
+ end
8
+
9
+ protected
10
+
11
+ def http_purge?(env)
12
+ env['REQUEST_METHOD'] == 'PURGE'
13
+ end
14
+
15
+ def http_purge(env)
16
+ Purger.new(env).purge(Rack::Request.new(env).url)
17
+ [200, {}, 'Purged']
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,48 @@
1
+ require 'rack/cache/key'
2
+ require 'rack/mock'
3
+
4
+ module Rack
5
+ module Cache
6
+ class Purge
7
+ class Purger
8
+ attr_reader :env
9
+
10
+ def initialize(env)
11
+ @env = env
12
+ end
13
+
14
+ def purge(uris)
15
+ normalize_uris(uris).map do |uri|
16
+ key = key_for(uri)
17
+ metastore.purge(key)
18
+ entitystore.purge(key)
19
+ end
20
+ end
21
+
22
+ protected
23
+
24
+ def normalize_uris(uris)
25
+ Array(uris).flatten.join("\n").split("\n")
26
+ end
27
+
28
+ def key_for(uri)
29
+ Rack::Cache::Key.call(Rack::Cache::Request.new(env_for(uri)))
30
+ end
31
+
32
+ def env_for(*args)
33
+ Rack::MockRequest.env_for(*args)
34
+ end
35
+
36
+ def metastore
37
+ @metastore ||= Rack::Cache::Storage.instance.resolve_metastore_uri(env['rack-cache.metastore'])
38
+ end
39
+
40
+ def entitystore
41
+ @entitystore ||= Rack::Cache::Storage.instance.resolve_entitystore_uri(env['rack-cache.entitystore'])
42
+ end
43
+ end
44
+
45
+ include Base
46
+ end
47
+ end
48
+ end
@@ -0,0 +1 @@
1
+ require 'rack/cache/purge'
@@ -0,0 +1,3 @@
1
+ module RackCachePurge
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rack-cache-purge
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-05 00:00:00 +02:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rack-cache
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ hash: 1
30
+ segments:
31
+ - 0
32
+ - 5
33
+ version: "0.5"
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ description: "[description]"
37
+ email: svenfuchs@artweb-design.de
38
+ executables: []
39
+
40
+ extensions: []
41
+
42
+ extra_rdoc_files: []
43
+
44
+ files:
45
+ - lib/rack/cache/purge/base.rb
46
+ - lib/rack/cache/purge/http.rb
47
+ - lib/rack/cache/purge/purger.rb
48
+ - lib/rack/cache/purge.rb
49
+ - lib/rack_cache_purge/version.rb
50
+ - lib/rack_cache_purge.rb
51
+ has_rdoc: true
52
+ homepage: http://github.com/svenfuchs/rack-cache-purge
53
+ licenses: []
54
+
55
+ post_install_message:
56
+ rdoc_options: []
57
+
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ hash: 3
66
+ segments:
67
+ - 0
68
+ version: "0"
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ hash: 3
75
+ segments:
76
+ - 0
77
+ version: "0"
78
+ requirements: []
79
+
80
+ rubyforge_project: "[none]"
81
+ rubygems_version: 1.3.7
82
+ signing_key:
83
+ specification_version: 3
84
+ summary: "[summary]"
85
+ test_files: []
86
+