sinatra-tinycache 0.1.2
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/README.markdown +35 -0
- data/lib/sinatra/tinycache.rb +32 -0
- metadata +75 -0
data/README.markdown
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
sinatra-tinycache
|
2
|
+
========
|
3
|
+
|
4
|
+
About
|
5
|
+
-----
|
6
|
+
An ultra simple key/value file cache for sinatra.
|
7
|
+
|
8
|
+
Install
|
9
|
+
-------
|
10
|
+
`gem install sinatra-tinycache`
|
11
|
+
|
12
|
+
Examples
|
13
|
+
--------
|
14
|
+
### Caching Views
|
15
|
+
require 'sinatra/tinycache'
|
16
|
+
class App < Sinatra::Base
|
17
|
+
helpers Sinatra::TinyCache
|
18
|
+
|
19
|
+
get '/'
|
20
|
+
if cache_expired?(:test_cache)
|
21
|
+
cache_data(erb(:slow_view))
|
22
|
+
end
|
23
|
+
load_cache_data(:test_cache)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
MIT License
|
28
|
+
-------
|
29
|
+
(c) 2009 Twoism Ltd
|
30
|
+
|
31
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
32
|
+
|
33
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
34
|
+
|
35
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'active_support/core_ext'
|
2
|
+
|
3
|
+
module Sinatra
|
4
|
+
module TinyCache
|
5
|
+
def cache_expired?(key, max_age=1.day)
|
6
|
+
return true unless File.exist?(cache_path(key))
|
7
|
+
cache_age(key) > max_age
|
8
|
+
end
|
9
|
+
|
10
|
+
def cache_data(key, data)
|
11
|
+
location = cache_path(key.to_s)
|
12
|
+
File.open(location, 'w') do |f|
|
13
|
+
f.puts data
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def load_cache_data(key)
|
18
|
+
location = cache_path(key.to_s)
|
19
|
+
return nil if !File.exist?(location)
|
20
|
+
file = File.open(location, 'r')
|
21
|
+
return file.read
|
22
|
+
end
|
23
|
+
|
24
|
+
def cache_path(key)
|
25
|
+
return File.join settings.cache, Digest::SHA1.hexdigest(key.to_s)
|
26
|
+
end
|
27
|
+
|
28
|
+
def cache_age(key)
|
29
|
+
(Time.now - File.ctime(cache_path(key))).to_i
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
metadata
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sinatra-tinycache
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 2
|
9
|
+
version: 0.1.2
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Ben Sales
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-06-26 00:00:00 +01:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: activesupport
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ~>
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 2
|
29
|
+
- 3
|
30
|
+
version: "2.3"
|
31
|
+
type: :runtime
|
32
|
+
version_requirements: *id001
|
33
|
+
description:
|
34
|
+
email: ben@twoism.co.uk
|
35
|
+
executables: []
|
36
|
+
|
37
|
+
extensions: []
|
38
|
+
|
39
|
+
extra_rdoc_files: []
|
40
|
+
|
41
|
+
files:
|
42
|
+
- README.markdown
|
43
|
+
- lib/sinatra/tinycache.rb
|
44
|
+
has_rdoc: true
|
45
|
+
homepage: http://code.twoism.co.uk
|
46
|
+
licenses: []
|
47
|
+
|
48
|
+
post_install_message:
|
49
|
+
rdoc_options: []
|
50
|
+
|
51
|
+
require_paths:
|
52
|
+
- lib
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
segments:
|
58
|
+
- 0
|
59
|
+
version: "0"
|
60
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
segments:
|
65
|
+
- 0
|
66
|
+
version: "0"
|
67
|
+
requirements: []
|
68
|
+
|
69
|
+
rubyforge_project:
|
70
|
+
rubygems_version: 1.3.6
|
71
|
+
signing_key:
|
72
|
+
specification_version: 3
|
73
|
+
summary: A tiny simple cache
|
74
|
+
test_files: []
|
75
|
+
|