sinatra-diskcache 0.0.3 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/README.md +70 -0
- data/lib/sinatra/diskcache.rb +3 -3
- data/lib/sinatra/version.rb +1 -1
- metadata +2 -2
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -2,7 +2,77 @@
|
|
2
2
|
|
3
3
|
Allows to cache heavy-load query results on the disk.
|
4
4
|
|
5
|
+
## Depends on
|
6
|
+
|
7
|
+
Nope. It doesn't have any dependencies.
|
8
|
+
|
5
9
|
## Install
|
6
10
|
|
7
11
|
gem install sinatra-diskcache
|
8
12
|
|
13
|
+
## Usage
|
14
|
+
|
15
|
+
Oh, it's pretty easy and straightforward. Look, I'll show you.
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
require 'sinatra'
|
19
|
+
require 'sinatra/diskcache'
|
20
|
+
|
21
|
+
# ... something clever here ...
|
22
|
+
|
23
|
+
get '/something' do
|
24
|
+
result = diskcache 'somefile' do |file| # this block will be invoked only in case of absence of 'somefile'
|
25
|
+
f = File.open file, 'w'
|
26
|
+
|
27
|
+
# heavy load here
|
28
|
+
sleep 5
|
29
|
+
|
30
|
+
f.write 'something to be cached'
|
31
|
+
f.close
|
32
|
+
end
|
33
|
+
|
34
|
+
send_file result # or transfer it anyhow else
|
35
|
+
end
|
36
|
+
```
|
37
|
+
|
38
|
+
Basically, that's all. For more detailed example you can look [here](https://github.com/pixe1f10w/scalls/).
|
39
|
+
|
40
|
+
## Avalilable options
|
41
|
+
|
42
|
+
* *diskcache_enabled*
|
43
|
+
|
44
|
+
Serves for activation/deactivasion of module. Defaults to 'true'.
|
45
|
+
|
46
|
+
* *diskcache_logging*
|
47
|
+
|
48
|
+
Activates/deactivates logging, mostly for debug. Defaults to 'true' in development environments.
|
49
|
+
|
50
|
+
* *diskcache_expiry_enabled*
|
51
|
+
|
52
|
+
Enabled cache file expiration. Period of expiration should be set by *diskcache_expiry_period* (see below). Defaults to 'true'.
|
53
|
+
|
54
|
+
* *diskcache_expiry_period*
|
55
|
+
|
56
|
+
See above. Value in seconds. Defaults to 3600 (1 hour).
|
57
|
+
|
58
|
+
* *diskcache_empty_cleanup*
|
59
|
+
|
60
|
+
Enables empty cache file deletion. Default to 'true'.
|
61
|
+
|
62
|
+
* *diskcache_path*
|
63
|
+
|
64
|
+
Declares the directory where cache files will be stored. Defaults to './diskcache'.
|
65
|
+
|
66
|
+
* *diskcache_full_paths*
|
67
|
+
|
68
|
+
Enables usage of absolute paths to cached files. Full file path will be passed to processing block and returned by 'diskcache' method. In the example above both 'result' and 'file' variables will have value of '/full/path/to/cached/file'.
|
69
|
+
|
70
|
+
Defaults to 'true'.
|
71
|
+
|
72
|
+
## License
|
73
|
+
|
74
|
+
Copyright © Ilia Zhirov - 2012.
|
75
|
+
|
76
|
+
Licensed under terms of [MIT license](http://www.opensource.org/licenses/mit-license.php).
|
77
|
+
|
78
|
+
Feel free to fork it, fix any bugs, add features and send me a pull requests. Bug reports are also welcome.
|
data/lib/sinatra/diskcache.rb
CHANGED
@@ -21,7 +21,7 @@ module Sinatra
|
|
21
21
|
end
|
22
22
|
rescue => e
|
23
23
|
throw e if settings.development? or settings.show_exceptions
|
24
|
-
|
24
|
+
|
25
25
|
if block_given?
|
26
26
|
block.call path_to filename
|
27
27
|
return resulting_name filename
|
@@ -45,7 +45,7 @@ module Sinatra
|
|
45
45
|
def cache_get filename
|
46
46
|
filepath = path_to filename
|
47
47
|
|
48
|
-
if not ( File.size?
|
48
|
+
if not ( File.size? filepath ) and settings.diskcache_empty_cleanup
|
49
49
|
cache_log "#{filename} is empty, wiping"
|
50
50
|
File.delete filepath
|
51
51
|
nil
|
@@ -65,7 +65,7 @@ module Sinatra
|
|
65
65
|
end
|
66
66
|
end
|
67
67
|
end
|
68
|
-
|
68
|
+
|
69
69
|
def self.registered app
|
70
70
|
app.helpers DiskCache::Helpers
|
71
71
|
|
data/lib/sinatra/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sinatra-diskcache
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-10-05 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Allows to cache heavy-load query results on the disk
|
15
15
|
email:
|