nesta-plugin-cache 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.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +14 -0
- data/README.md +67 -0
- data/Rakefile +2 -0
- data/lib/nesta-plugin-cache.rb +3 -0
- data/lib/nesta-plugin-cache/init.rb +52 -0
- data/lib/nesta-plugin-cache/version.rb +7 -0
- data/nesta-plugin-cache.gemspec +28 -0
- metadata +118 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
Copyright (c) 2012 Max Sadrieh
|
2
|
+
|
3
|
+
This program is free software: you can redistribute it and/or modify
|
4
|
+
it under the terms of the GNU General Public License as published by
|
5
|
+
the Free Software Foundation, either version 3 of the License, or
|
6
|
+
(at your option) any later version.
|
7
|
+
|
8
|
+
This program is distributed in the hope that it will be useful,
|
9
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
11
|
+
GNU General Public License for more details.
|
12
|
+
|
13
|
+
You should have received a copy of the GNU General Public License
|
14
|
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
data/README.md
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
# Nesta::Plugin::Cache
|
2
|
+
|
3
|
+
This plugin provides caching directives on each page that lets Nesta return
|
4
|
+
appropriate caching headers to the client and any proxy between the server and
|
5
|
+
the client. This improves performance.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'nesta-plugin-cache'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install nesta-plugin-cache
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
### Global settings
|
24
|
+
|
25
|
+
Set the entries `expires` and `expires\_type` to the appropriate values in your
|
26
|
+
`config.yml`.
|
27
|
+
|
28
|
+
expires
|
29
|
+
The amount of time each page can be cached for by the client. If your
|
30
|
+
pages changes very often, set this to a small value. If on the other hand
|
31
|
+
your pages are mostly static, set it to a large value. Within the time you
|
32
|
+
put, a browser that has a copy of the file in its cache might choose not
|
33
|
+
to requery your website for the latest version. Can be overriden in
|
34
|
+
individual pages. In seconds.
|
35
|
+
Default: 0
|
36
|
+
|
37
|
+
expires: 3600
|
38
|
+
|
39
|
+
expires\_type
|
40
|
+
Whether or not proxies can cache the pages we serve. If set to public,
|
41
|
+
both proxies between the browser and the web server and the browser itself
|
42
|
+
can cache the pages. If set to private, only the client's browser can.
|
43
|
+
In practice, if the pages are modified depending on who requests
|
44
|
+
them, you should set this to private. Otherwise if all clients get the
|
45
|
+
same page (usually the case, particularly on nesta websites), set it to
|
46
|
+
public.
|
47
|
+
Default: public
|
48
|
+
|
49
|
+
expires\_type: private
|
50
|
+
|
51
|
+
### Per-page settings
|
52
|
+
|
53
|
+
If you want to change the global settings on a page by page basis (for a page
|
54
|
+
that is updated very often for example), you can set the appropriate meta data
|
55
|
+
fields: `Expires` and `Expires Type`.
|
56
|
+
|
57
|
+
For more info on the expires types, see the following RFC:
|
58
|
+
|
59
|
+
* http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9.1
|
60
|
+
|
61
|
+
## Contributing
|
62
|
+
|
63
|
+
1. Fork it
|
64
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
65
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
66
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
67
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
module Nesta
|
2
|
+
module Plugin
|
3
|
+
module Cache
|
4
|
+
module Helpers
|
5
|
+
# If your plugin needs any helper methods, add them here...
|
6
|
+
end
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
class Config
|
11
|
+
@settings += %w[expires expires_type]
|
12
|
+
end
|
13
|
+
|
14
|
+
class Page
|
15
|
+
def expires
|
16
|
+
metadata('expires').nil? ? nil : metadata('expires').to_i
|
17
|
+
end
|
18
|
+
|
19
|
+
def expires_type
|
20
|
+
metadata('expires type').nil? ? nil : metadata('expires type').to_sym
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
class App
|
25
|
+
helpers Nesta::Plugin::Cache::Helpers
|
26
|
+
|
27
|
+
# Add the Nesta config entries to the Sinatra settings object
|
28
|
+
set :expires_time, Config.expires
|
29
|
+
set :expires_type, (Config.expires_type.nil? ?
|
30
|
+
nil : Config.expires_type.to_sym)
|
31
|
+
|
32
|
+
# The default expires values
|
33
|
+
before do
|
34
|
+
unless settings.expires_time.nil?
|
35
|
+
expires settings.expires_time,
|
36
|
+
settings.expires_type || :public,
|
37
|
+
:must_revalidate
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
after do
|
42
|
+
# Check that this is a regular page (ie not the sitemap, atom feed, an
|
43
|
+
# attachement or a CSS stylesheet): these don't have metadata; and check
|
44
|
+
# that the page defined a per-page expires directive.
|
45
|
+
unless @page.nil? || @page.expires.nil?
|
46
|
+
expires @page.expires,
|
47
|
+
@page.expires_type || settings.expires_type || :public,
|
48
|
+
:must_revalidate
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/nesta-plugin-cache/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Max Sadrieh"]
|
6
|
+
gem.email = ["max.sadrieh@gmail.com"]
|
7
|
+
gem.description = %q{Cache-control headers plugin for Nesta, a Ruby CMS}
|
8
|
+
gem.summary = <<-EOF
|
9
|
+
This Nesta plugin lets you define cache control headers globally for your site
|
10
|
+
or on a page by page basis. This can improve performance tremendously since the
|
11
|
+
client browsers can use cached versions of your pages for a set amount of time.
|
12
|
+
|
13
|
+
The global values are set in the config.yml by using expires and expires_type
|
14
|
+
and the per-page values are defined in each page's metadata by using the
|
15
|
+
Expires and Expires Type fields.
|
16
|
+
EOF
|
17
|
+
gem.homepage = "http://www.sadrieh.me/projects/nesta-plugin-cache"
|
18
|
+
|
19
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
gem.files = `git ls-files`.split("\n")
|
21
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
22
|
+
gem.name = "nesta-plugin-cache"
|
23
|
+
gem.require_paths = ["lib"]
|
24
|
+
gem.version = Nesta::Plugin::Cache::VERSION
|
25
|
+
gem.add_dependency("nesta", "~> 0.9.11")
|
26
|
+
gem.add_dependency("sinatra", "~> 1.2")
|
27
|
+
gem.add_development_dependency("rake")
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nesta-plugin-cache
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Max Sadrieh
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2012-03-31 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: nesta
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ~>
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 45
|
29
|
+
segments:
|
30
|
+
- 0
|
31
|
+
- 9
|
32
|
+
- 11
|
33
|
+
version: 0.9.11
|
34
|
+
type: :runtime
|
35
|
+
version_requirements: *id001
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: sinatra
|
38
|
+
prerelease: false
|
39
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ~>
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
hash: 11
|
45
|
+
segments:
|
46
|
+
- 1
|
47
|
+
- 2
|
48
|
+
version: "1.2"
|
49
|
+
type: :runtime
|
50
|
+
version_requirements: *id002
|
51
|
+
- !ruby/object:Gem::Dependency
|
52
|
+
name: rake
|
53
|
+
prerelease: false
|
54
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
hash: 3
|
60
|
+
segments:
|
61
|
+
- 0
|
62
|
+
version: "0"
|
63
|
+
type: :development
|
64
|
+
version_requirements: *id003
|
65
|
+
description: Cache-control headers plugin for Nesta, a Ruby CMS
|
66
|
+
email:
|
67
|
+
- max.sadrieh@gmail.com
|
68
|
+
executables: []
|
69
|
+
|
70
|
+
extensions: []
|
71
|
+
|
72
|
+
extra_rdoc_files: []
|
73
|
+
|
74
|
+
files:
|
75
|
+
- .gitignore
|
76
|
+
- Gemfile
|
77
|
+
- LICENSE
|
78
|
+
- README.md
|
79
|
+
- Rakefile
|
80
|
+
- lib/nesta-plugin-cache.rb
|
81
|
+
- lib/nesta-plugin-cache/init.rb
|
82
|
+
- lib/nesta-plugin-cache/version.rb
|
83
|
+
- nesta-plugin-cache.gemspec
|
84
|
+
homepage: http://www.sadrieh.me/projects/nesta-plugin-cache
|
85
|
+
licenses: []
|
86
|
+
|
87
|
+
post_install_message:
|
88
|
+
rdoc_options: []
|
89
|
+
|
90
|
+
require_paths:
|
91
|
+
- lib
|
92
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
93
|
+
none: false
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
hash: 3
|
98
|
+
segments:
|
99
|
+
- 0
|
100
|
+
version: "0"
|
101
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
|
+
none: false
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
hash: 3
|
107
|
+
segments:
|
108
|
+
- 0
|
109
|
+
version: "0"
|
110
|
+
requirements: []
|
111
|
+
|
112
|
+
rubyforge_project:
|
113
|
+
rubygems_version: 1.8.15
|
114
|
+
signing_key:
|
115
|
+
specification_version: 3
|
116
|
+
summary: This Nesta plugin lets you define cache control headers globally for your site or on a page by page basis. This can improve performance tremendously since the client browsers can use cached versions of your pages for a set amount of time. The global values are set in the config.yml by using expires and expires_type and the per-page values are defined in each page's metadata by using the Expires and Expires Type fields.
|
117
|
+
test_files: []
|
118
|
+
|