disk_cache 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +71 -0
- data/Rakefile +6 -0
- data/disk_cache.gemspec +22 -0
- data/lib/disk_cache/version.rb +3 -0
- data/lib/disk_cache.rb +149 -0
- data/spec/asset/Trollface.svg +110 -0
- data/spec/file_cache/file_cache_spec.rb +34 -0
- data/spec/spec_helper.rb +1 -0
- metadata +98 -0
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Maximilian Haack
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
# DiskCache
|
2
|
+
|
3
|
+
[![Build Status](https://secure.travis-ci.org/propertybase/disk_cache.png)](https://travis-ci.org/propertybase/disk_cache)
|
4
|
+
|
5
|
+
What does it do? You give DiskCache the URL of a file and DiskCache makes sure
|
6
|
+
that it has the file stored on disk. You can retrieve your files with the same
|
7
|
+
URL you used to save the file.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
gem 'disk_cache'
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install disk_cache
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
# to save an image in the cache
|
27
|
+
DiskCache.put('http://example.com/1234abc.jpg')
|
28
|
+
#=> nil
|
29
|
+
|
30
|
+
# to get an image from the cache
|
31
|
+
DiskCache.get('http://example.com/1234abc.jpg')
|
32
|
+
#=> #<File:1234abc.jpg>
|
33
|
+
# or
|
34
|
+
#=> nil # if the file isn't stored in the cache
|
35
|
+
|
36
|
+
# to get a file no matter if it was stored in the cache or not
|
37
|
+
# this will get the file from disk or download it and save it in the cache
|
38
|
+
DiskCache.pget('http://example.com/1234abc.jpg')
|
39
|
+
#=> #<File:1234abc.jpg>
|
40
|
+
|
41
|
+
# to delete an image from the cache
|
42
|
+
DiskCache.del('http://example.com/1234abc.jpg')
|
43
|
+
#=> nil
|
44
|
+
```
|
45
|
+
|
46
|
+
|
47
|
+
## Ideas
|
48
|
+
|
49
|
+
- option to check if an image has changed (i.e. HTTP Last-Modified)
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
Net::HTTP.start("example.com") do |http|
|
53
|
+
response = http.request_head('/1352127364208.png')
|
54
|
+
puts response['Last-Modified']
|
55
|
+
end
|
56
|
+
```
|
57
|
+
|
58
|
+
- option to change the path of the cache
|
59
|
+
|
60
|
+
- option to force a .put, i.e. overwrite
|
61
|
+
|
62
|
+
- option to set the depth of subfolders
|
63
|
+
|
64
|
+
|
65
|
+
## Contributing
|
66
|
+
|
67
|
+
1. Fork it
|
68
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
69
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
70
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
71
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/disk_cache.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'disk_cache/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "disk_cache"
|
8
|
+
gem.version = DiskCache::VERSION
|
9
|
+
gem.authors = ["Maximilian Haack"]
|
10
|
+
gem.email = ["mxhaack@gmail.com"]
|
11
|
+
gem.description = %q{A simple way to cache your files.}
|
12
|
+
gem.summary = %q{Cache files that you have have to use several times.}
|
13
|
+
gem.homepage = ""
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_development_dependency "rake"
|
21
|
+
gem.add_development_dependency "rspec"
|
22
|
+
end
|
data/lib/disk_cache.rb
ADDED
@@ -0,0 +1,149 @@
|
|
1
|
+
require 'disk_cache/version'
|
2
|
+
require 'open-uri'
|
3
|
+
require 'digest/sha2'
|
4
|
+
|
5
|
+
module DiskCache
|
6
|
+
extend self
|
7
|
+
|
8
|
+
# Public: save a file to the cache
|
9
|
+
#
|
10
|
+
# url - The URL to the file
|
11
|
+
#
|
12
|
+
# Example:
|
13
|
+
#
|
14
|
+
# DiskCache.put('http://example.com/test123.jpg')
|
15
|
+
# #=> nil
|
16
|
+
#
|
17
|
+
# Returns: nil
|
18
|
+
def put(url)
|
19
|
+
file = filepath(url)
|
20
|
+
return nil if File.exist?(file)
|
21
|
+
|
22
|
+
FileUtils.mkdir_p path(url)
|
23
|
+
File.open(file, "wb") { |f| f << open(url).read }
|
24
|
+
nil
|
25
|
+
end
|
26
|
+
|
27
|
+
# Public: get a file from the cache
|
28
|
+
#
|
29
|
+
# url - The URL to the file
|
30
|
+
#
|
31
|
+
# Examples:
|
32
|
+
#
|
33
|
+
# DiskCache.get('http://example.com/test123.jpg')
|
34
|
+
# # => #<File:9ae274d94c34542ddd1b64667c1d4e392211ff67>
|
35
|
+
#
|
36
|
+
# DiskCache.get('http://example.com/test123.jpg')
|
37
|
+
# # => nil
|
38
|
+
#
|
39
|
+
# Returns the File or nil
|
40
|
+
def get(url)
|
41
|
+
File.open(filepath(url), "rb")
|
42
|
+
rescue Errno::ENOENT
|
43
|
+
nil
|
44
|
+
end
|
45
|
+
|
46
|
+
# Public: get a file and save it to the cache if it isn't there already
|
47
|
+
#
|
48
|
+
# url - The URL to the file
|
49
|
+
#
|
50
|
+
# Examples:
|
51
|
+
#
|
52
|
+
# DiskCache.get('http://example.com/test123.jpg')
|
53
|
+
# # => #<File:9ae274d94c34542ddd1b64667c1d4e392211ff67>
|
54
|
+
#
|
55
|
+
# Returns a File
|
56
|
+
def pget(url)
|
57
|
+
put(url)
|
58
|
+
get(url)
|
59
|
+
end
|
60
|
+
|
61
|
+
# Public: delete a file from the cache
|
62
|
+
#
|
63
|
+
# url - The URL to the file
|
64
|
+
#
|
65
|
+
# Example:
|
66
|
+
#
|
67
|
+
# DiskCache.del('http://example.com/test123.jpg')
|
68
|
+
# # => nil
|
69
|
+
#
|
70
|
+
# Returns nil
|
71
|
+
def del(url)
|
72
|
+
FileUtils.rm filepath(url), force: true
|
73
|
+
end
|
74
|
+
|
75
|
+
private
|
76
|
+
|
77
|
+
# Internal: Hashes a given piece of data with SHA1
|
78
|
+
#
|
79
|
+
# datum - piece of data to be hashed
|
80
|
+
#
|
81
|
+
# Examples:
|
82
|
+
#
|
83
|
+
# hash('hi')
|
84
|
+
# # => "c22b5f9178342609428d6f51b2c5af4c0bde6a42"
|
85
|
+
#
|
86
|
+
# Returns String with hexdigest
|
87
|
+
def hash(datum)
|
88
|
+
@hasher ||= Digest::SHA1.new
|
89
|
+
@hasher.hexdigest(datum)
|
90
|
+
end
|
91
|
+
|
92
|
+
# Internal: Return the directory of the cache as a String
|
93
|
+
def cache_dir
|
94
|
+
Dir.pwd + '/cache/'
|
95
|
+
end
|
96
|
+
|
97
|
+
# Internal: Calculate a path from a hash
|
98
|
+
#
|
99
|
+
# hsh - the hash
|
100
|
+
#
|
101
|
+
# Example:
|
102
|
+
#
|
103
|
+
# path_h('9ae274d94c34542ddd1b64667c1d4e392211ff67')
|
104
|
+
# # => "cache/9a/e2/"
|
105
|
+
def path_h(hsh)
|
106
|
+
dir = hsh[0..1] + '/'
|
107
|
+
subdir = hsh[2..3] + '/'
|
108
|
+
cache_dir + dir + subdir
|
109
|
+
end
|
110
|
+
|
111
|
+
# Internal: calculate the path from a URL
|
112
|
+
#
|
113
|
+
# url - The URL to the file
|
114
|
+
#
|
115
|
+
# Example:
|
116
|
+
#
|
117
|
+
# path('http://example.com/test123.jpg')
|
118
|
+
# # => "cache/9a/e2/"
|
119
|
+
def path(url)
|
120
|
+
path_h hash(url)
|
121
|
+
end
|
122
|
+
|
123
|
+
# Internal: calculate the filename from a hash
|
124
|
+
#
|
125
|
+
# hsh - the hash
|
126
|
+
#
|
127
|
+
# Example:
|
128
|
+
#
|
129
|
+
# filename_h('9ae274d94c34542ddd1b64667c1d4e392211ff67')
|
130
|
+
# # => "74d94c34542ddd1b64667c1d4e392211ff67"
|
131
|
+
def filename_h(hsh)
|
132
|
+
hsh[4..-1]
|
133
|
+
end
|
134
|
+
|
135
|
+
# Internal: calculate the path/filename of a file's URL
|
136
|
+
#
|
137
|
+
# url - the URL of the file
|
138
|
+
#
|
139
|
+
# Example:
|
140
|
+
#
|
141
|
+
# filepath!('http://example.com/test123.jpg')
|
142
|
+
# # => "cache/9a/e2/74d94c34542ddd1b64667c1d4e392211ff67"
|
143
|
+
#
|
144
|
+
# Returns a Sting with the full path and filename
|
145
|
+
def filepath(url)
|
146
|
+
hsh = hash url
|
147
|
+
path_h(hsh) + filename_h(hsh)
|
148
|
+
end
|
149
|
+
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
2
|
+
<!-- Generator: Adobe Illustrator 15.1.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
|
3
|
+
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
4
|
+
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
|
5
|
+
width="365px" height="290px" viewBox="0 0 365 290" enable-background="new 0 0 365 290" xml:space="preserve">
|
6
|
+
<g>
|
7
|
+
<path fill-rule="evenodd" clip-rule="evenodd" d="M186.523,42.629c-5.146,4.192-9.271,9.407-9.339,18.68
|
8
|
+
C173.461,53.847,177.921,43.395,186.523,42.629z"/>
|
9
|
+
<path fill-rule="evenodd" clip-rule="evenodd" d="M123.948,53.836c7.713-4.167,10.029,14.72,5.604,19.613
|
10
|
+
C130.161,64.435,129.688,56.502,123.948,53.836z"/>
|
11
|
+
<path fill-rule="evenodd" clip-rule="evenodd" d="M258.439,84.657c-6.472,7.459-15.34,1.071-24.283,0
|
12
|
+
c-19.291-2.311-37.813,6.279-51.368,12.142c-30.483-15.506,8.09-36.934,38.293-35.49C241.571,62.287,255.368,71.441,258.439,84.657
|
13
|
+
z M206.138,68.78c-9.442,5.189-24.801,4.463-25.218,18.679c13.235,0.783,15.879-9.026,28.953-8.405
|
14
|
+
C208.595,75.662,209.309,70.278,206.138,68.78z M249.1,80.922c-0.981-4.312-4.509-6.076-10.273-5.604
|
15
|
+
C238.269,81.168,246.137,78.592,249.1,80.922z"/>
|
16
|
+
<path fill-rule="evenodd" clip-rule="evenodd" d="M135.156,84.657c4.476-1.044,8.57-2.613,12.142,0
|
17
|
+
c-0.284,6.877-7.897,6.424-12.142,9.34c0,5.915,0,11.83,0,17.745c-5.259,4.703-12.976,6.949-16.812,13.076
|
18
|
+
c3.135,8.071,8.689,13.726,15.877,17.745c4.63-0.261,6.327-5.545,11.208-2.802c-6.817,22.618-25.415,0.727-32.689-8.406
|
19
|
+
c-2.53,1.206-3.32,4.151-7.472,3.736c0.448-2.938-1.33-3.651-1.868-5.604c-7.304,1.725-10.321,7.736-19.613,7.472
|
20
|
+
c16.933-7.661,29.157-20.031,43.896-29.887c0-4.358,0-8.717,0-13.075c-12.206-8.964-38.5-3.84-52.302-11.208
|
21
|
+
C83.698,60.844,125.495,70.63,135.156,84.657z M88.458,79.054c4.574,1.797,12.003,0.818,15.877-0.935
|
22
|
+
C99.76,76.322,92.331,77.302,88.458,79.054z"/>
|
23
|
+
<path fill-rule="evenodd" clip-rule="evenodd" d="M262.175,78.119c3.953-1.745,9.671,2.763,15.878,1.868
|
24
|
+
c0.017,4.97-8.155,5.776-12.142,3.736c0.127-2.676,6.411,0.807,6.538-1.868C269.202,80.433,264.614,80.351,262.175,78.119z"/>
|
25
|
+
<path fill-rule="evenodd" clip-rule="evenodd" d="M71.646,81.855c-23.154-1.819-48.734,7.468-49.5,29.887
|
26
|
+
c-0.111,3.249,0.055,10.499,2.802,14.943c4.358,7.051,15.351,3.564,18.679,13.076c-17.196-4.129-25.099-13.865-23.349-30.821
|
27
|
+
C22.707,85.399,45.711,76.568,71.646,81.855z"/>
|
28
|
+
<path fill-rule="evenodd" clip-rule="evenodd" d="M335.024,98.667c-6.505-12.485-20.566-17.415-41.095-15.878
|
29
|
+
C309.887,79.15,332.258,83.12,335.024,98.667z"/>
|
30
|
+
<path fill-rule="evenodd" clip-rule="evenodd" d="M262.175,87.459c1.246-2.656,4.153,0.721,5.604,0.935
|
31
|
+
C266.478,91.106,263.17,88.129,262.175,87.459z"/>
|
32
|
+
<path fill-rule="evenodd" clip-rule="evenodd" d="M219.213,88.394c9.786,1.591,14.354,12.004,26.151,13.075
|
33
|
+
c14.428,1.31,21.944-8.832,34.557-12.142c34.323-9.008,62.154,22.959,36.425,50.435c-4.15-9.265,4.082-13.921,2.802-25.218
|
34
|
+
c-1.492-13.156-14.128-21.953-28.953-19.613c-4.989,0.788-9.372,6.17-14.943,8.406C255.177,111.395,219.595,110.784,219.213,88.394
|
35
|
+
z"/>
|
36
|
+
<path fill-rule="evenodd" clip-rule="evenodd" d="M45.495,90.261c-3.193,5.843-16.902,9.244-12.142,26.151
|
37
|
+
c-4.729-4.163,0.298-12.912-0.934-19.613C36.929,94.771,41.102,92.406,45.495,90.261z"/>
|
38
|
+
<path fill-rule="evenodd" clip-rule="evenodd" d="M84.722,108.007c4.129-1.163,5.093-5.492,11.208-4.67
|
39
|
+
c3.946,12.136-11.755,12.458-23.349,12.142c-1-4.604-2.942-8.267-6.538-10.274c-10.696-1.044-17.042,2.26-26.151,2.803
|
40
|
+
C44.802,88.732,76.079,99.026,84.722,108.007z"/>
|
41
|
+
<path fill-rule="evenodd" clip-rule="evenodd" d="M313.543,127.62c-4.974,1.819-8.905-0.382-14.009-0.935
|
42
|
+
c-3.296,2.591-6.112,8.619-3.736,14.01c-11.935,10.238-19.867,29.062-31.755,42.028c-29.346,32.013-80.396,45.875-146.633,42.963
|
43
|
+
c-21.421-0.941-46.364-3.273-56.972-14.01c-16.806-17.009-17.606-69.736-2.802-90.595c1.437-2.922-0.408-9.125,2.802-10.273
|
44
|
+
c7.459,2.57,3.389,13.441,5.604,19.613c4.615,12.864,30.345,21.159,48.566,23.35c68.329,8.211,126.044-27.586,170.916-42.963
|
45
|
+
c1.343-3.327,0.954-8.386,3.736-10.273c5.58,1.948,3.293,6.625,5.604,10.273C299.982,118.893,312.243,119.485,313.543,127.62z
|
46
|
+
M256.571,133.224c0,4.67,0,9.34,0,14.01c17.53-3.018,32.683-8.412,33.623-28.02C274.791,119.688,268.945,129.72,256.571,133.224z
|
47
|
+
M57.636,143.497c2.292-0.261,4.305-5.573,2.802-6.538C59.663,139.297,57.879,140.628,57.636,143.497z M205.203,149.102
|
48
|
+
c-0.035,6.262,2.396,10.057,2.802,15.877c15.756-6.971,39.716-5.737,41.095-27.085C235.18,138.609,220.17,146.32,205.203,149.102z
|
49
|
+
M66.976,166.847c0.883-6.916,5.052-16.135,0.934-22.415C64.852,149.008,57.265,163.712,66.976,166.847z M257.505,174.318
|
50
|
+
c2.373-1.989,5.732-3.469,8.406-6.538c3.599-4.131,10.779-16.792,9.34-16.812C264.421,152.788,248.867,162.037,257.505,174.318z
|
51
|
+
M77.25,170.582c4.59-1.431,8.138,3.009,10.274,0.935c-3.352-5.56,3.273-9.159,2.802-14.943c-5.494-0.11-7.863-3.345-12.142-4.67
|
52
|
+
C73.106,155.974,76.713,164.221,77.25,170.582z M195.863,152.837c-11.24,2.77-23.607,4.412-34.557,7.472c0,4.67,0,9.34,0,14.01
|
53
|
+
c16.108,1.165,26.879-3.008,39.227-5.604C199.478,162.921,199.495,156.055,195.863,152.837z M94.061,171.517
|
54
|
+
c8.027,2.247,17.244,3.304,28.019,2.802c-0.616-4.475,0.96-10.269,0-12.142c-8.43-0.91-18.129-0.551-24.283-3.735
|
55
|
+
C96.551,162.799,96.351,168.202,94.061,171.517z M131.42,162.177c0.224,4.894-2.273,7.066-2.802,11.208
|
56
|
+
c6.938,2.091,17.681,0.376,26.151,0.934c0-4.67,0-9.34,0-14.01C145.928,159.874,140.743,163.094,131.42,162.177z M211.741,178.055
|
57
|
+
c-1.32,11.904,6.023,15.146,7.472,24.283c13.203-5.166,22.749-13.987,33.623-21.481c-5.313-2.472-4.873-10.694-6.538-16.812
|
58
|
+
C236.302,170.238,224.683,174.807,211.741,178.055z M168.778,190.196c-0.727,9.132,1.317,15.493,0.934,24.282
|
59
|
+
c18.011,1.2,29.297-4.325,42.029-8.405c-2.256-9.264-8.135-14.903-8.406-26.151C193.193,184.724,182.508,188.981,168.778,190.196z
|
60
|
+
M66.042,203.271c-0.139-7.333-3.821-11.122-7.472-14.943C60.173,194.196,62.315,199.526,66.042,203.271z M83.788,211.677
|
61
|
+
c-2.131-7.831-4.333-15.592-11.208-18.679c-0.543,5.212,2.791,6.548,2.802,11.207c-0.58,3.212-5.024,1.893-5.604,2.802
|
62
|
+
C73.072,209.939,78.548,210.689,83.788,211.677z M133.288,195.8c0.056,8.038,3.105,13.084,2.802,21.481
|
63
|
+
c8.71-0.318,18.873,0.815,26.151-0.935c-0.284-4.262-1.548-15.125-0.934-23.349C152.832,194.852,141.989,197.003,133.288,195.8z
|
64
|
+
M92.193,212.611c3.603,1.378,7.057,2.905,12.142,2.802c-1.25-6.222-5.409-9.535-5.604-16.812
|
65
|
+
c-4.921-0.06-6.855-3.107-12.142-2.802C87.456,202.192,94.924,205.574,92.193,212.611z M106.203,197.668
|
66
|
+
c1.691,7.025,5.9,11.534,7.472,18.679c4.415,0.281,11.899,2.389,15.877,0C128.68,203.571,121.551,192.951,106.203,197.668z"/>
|
67
|
+
<path fill-rule="evenodd" clip-rule="evenodd" d="M197.731,121.082c0.981,11.655-1.498,23.475-13.075,19.613
|
68
|
+
c-1.245-8.125,8.42-7.704,6.537-14.01c-1.758-5.887-9.642-2.651-16.811-5.604C176.042,109.851,193.845,115.804,197.731,121.082z"/>
|
69
|
+
<path fill-rule="evenodd" clip-rule="evenodd" d="M200.533,115.479c3.937-0.161,0.641,2.091,0,2.802
|
70
|
+
c3.373,10.495,23.844-1.871,28.02,7.472C220.211,119.987,196.217,130.807,200.533,115.479z"/>
|
71
|
+
<path fill-rule="evenodd" clip-rule="evenodd" d="M31.485,117.346c3.703,3.146,6.414,7.285,11.208,9.34
|
72
|
+
C37.045,129.198,31.933,123.141,31.485,117.346z"/>
|
73
|
+
<path fill-rule="evenodd" clip-rule="evenodd" d="M180.92,129.487c-0.19,2.923,0.63,6.856-0.934,8.406
|
74
|
+
c-5.957-4.733-16.772,0.167-25.217-2.802C155.783,124.985,172.876,127.209,180.92,129.487z"/>
|
75
|
+
<path fill-rule="evenodd" clip-rule="evenodd" d="M258.439,207.007c1.207,2.192-6.614,3.027-10.273,4.67
|
76
|
+
c-27.143,12.185-56.536,34.2-97.133,30.821C197.218,241.051,221.287,217.487,258.439,207.007z"/>
|
77
|
+
<path fill-rule="evenodd" clip-rule="evenodd" d="M65.108,225.687c9.354,12.75,27.871,16.337,48.566,17.745
|
78
|
+
C93.812,244.924,68.588,243.69,65.108,225.687z"/>
|
79
|
+
<path fill-rule="evenodd" clip-rule="evenodd" d="M161.307,232.225c-13.334,0.617-33.814,3.582-48.566,0.934
|
80
|
+
c0.823,0.147-5.321,1.021-1.868-0.934C128.293,233.028,146.332,230.921,161.307,232.225z"/>
|
81
|
+
<path fill-rule="evenodd" clip-rule="evenodd" d="M127.684,243.432c3.443-2.16,10.882-0.325,15.877-0.934
|
82
|
+
C140.118,244.658,132.679,242.823,127.684,243.432z"/>
|
83
|
+
<path fill-rule="evenodd" clip-rule="evenodd" d="M38.023,42.629C82.539,0.251,168.45,6.151,250.968,7.138
|
84
|
+
c7.848,0.094,16.719-1.368,23.349,0c11.871,2.451,25.224,17.023,31.755,28.02c4.845,8.154,7.067,20.015,11.208,27.085
|
85
|
+
c13.085,22.346,46.477,27.908,37.358,67.245c-4.239,18.291-23.693,25.693-33.623,43.897c-3.577,6.559-4.243,13.956-7.472,19.613
|
86
|
+
c-12.425,21.775-44.768,38.018-71.915,50.434c-20.634,9.438-43.315,23.67-62.576,28.953c-12.695,3.482-31.551,6.412-50.435,10.273
|
87
|
+
c-27.106,5.544-57.922,8.286-79.387-0.934c-11.146-4.787-23.773-16.287-26.151-27.085c-5.578-25.329,11.102-67.953,3.736-98.066
|
88
|
+
c-5.056-20.67-22.906-34.925-16.812-60.708C15.172,74.001,40.463,75.064,38.023,42.629z M346.232,130.422
|
89
|
+
c10.41-28.818-14.1-53.59-47.633-52.303c6.19-2.108,12.84-0.034,19.613,0c-16.228-19.917-20.158-60.96-54.17-64.443
|
90
|
+
c-47.05-4.819-108.237,1.462-153.17,5.604c31.311,8.204,65.113-5.872,98.067-2.802c30.411,2.834,51.748,21.332,68.18,35.491
|
91
|
+
c-19.244-10.752-39.329-30.848-69.114-33.623c-24.766-2.308-42.278,4.428-63.51,5.604c-17.014,0.942-34.695-3.396-49.5-1.868
|
92
|
+
c-17.392,1.796-47.009,16.645-51.368,29.888c-1.588,4.823,0.142,10.746-1.868,15.877c-7.14,18.231-32.366,23.279-23.349,54.17
|
93
|
+
c2.51,8.6,9.292,13.555,12.142,19.614c8.393,17.847,5.012,46.601,2.802,68.18c-1.381,13.484-5.358,29.068-2.802,42.028
|
94
|
+
c6.843,34.686,73.448,29.463,105.539,21.481c11.469-2.854,21.589-8.207,30.821-9.34c4.057-0.498,8.442,1.187,14.944,0
|
95
|
+
c9.153-1.672,21.952-11.397,32.688-16.812c31.866-16.069,75.01-30.342,92.463-57.906c4.461-7.046,6.14-18.473,9.34-24.283
|
96
|
+
c2.247-4.08,8.411-4.896,7.472-10.273c0.399,1.505-3.482,3.134-3.736,0.934C331.436,150.569,342.594,140.495,346.232,130.422z"/>
|
97
|
+
<path fill-rule="evenodd" clip-rule="evenodd" d="M77.25,36.091c7.441-13.146,29.974-2.976,47.632-2.802
|
98
|
+
c26.067,0.258,51.737-8.142,75.651-6.538c28.813,1.933,54.964,15.638,69.114,32.689c-18.568-14.5-45.291-31.016-81.256-30.821
|
99
|
+
c-19.053,0.104-38.58,7.634-63.51,6.538C106.123,34.332,89.279,27.845,77.25,36.091z"/>
|
100
|
+
<path fill-rule="evenodd" clip-rule="evenodd" d="M182.788,39.827c-2.311,0.118-1.588-1.144,0-0.935
|
101
|
+
c32.046-2.848,63.885,1.937,74.717,23.35C243.382,43.987,216.276,38.717,182.788,39.827z"/>
|
102
|
+
<path fill-rule="evenodd" clip-rule="evenodd" d="M134.222,48.232c-17.639-5.811-54.154-8.276-59.774,13.076
|
103
|
+
c-2.662-13.006,18.243-20.401,38.292-19.614C120.785,42.011,131.524,42.773,134.222,48.232z"/>
|
104
|
+
<path fill-rule="evenodd" clip-rule="evenodd" d="M315.411,148.167c19.058-3.155,22.938-26.103,19.613-48.566
|
105
|
+
c5.83,13.193,0.506,26.607-0.934,40.161C328.267,142.967,324.55,148.277,315.411,148.167z"/>
|
106
|
+
<path fill-rule="evenodd" clip-rule="evenodd" d="M47.363,228.488c2.129,1.295,0.348,6.501,0.934,9.34
|
107
|
+
c35.593,29.644,117.108,12.831,158.774-0.934c25.871-8.547,47.983-23.19,71.915-29.888
|
108
|
+
c-38.938,26.75-124.252,53.648-195.199,48.566C67.182,254.384,43.721,247.924,47.363,228.488z"/>
|
109
|
+
</g>
|
110
|
+
</svg>
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe DiskCache do
|
4
|
+
let(:path) { 'spec/asset/Trollface.svg' }
|
5
|
+
let(:file) { File.open(path, 'r') }
|
6
|
+
|
7
|
+
context "storing and accessing" do
|
8
|
+
it ".put" do
|
9
|
+
DiskCache.put(path)
|
10
|
+
DiskCache.get(path).should_not be_nil
|
11
|
+
end
|
12
|
+
|
13
|
+
it ".get" do
|
14
|
+
DiskCache.put(path)
|
15
|
+
file_from_cache = DiskCache.get(path)
|
16
|
+
FileUtils.compare_file(file, file_from_cache).should be_true
|
17
|
+
end
|
18
|
+
|
19
|
+
it ".pget" do
|
20
|
+
DiskCache.del(path)
|
21
|
+
file_from_cache = DiskCache.pget(path)
|
22
|
+
FileUtils.compare_file(file, file_from_cache).should be_true
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context "removing data" do
|
27
|
+
before(:each) { DiskCache.put(path) }
|
28
|
+
|
29
|
+
it ".delete" do
|
30
|
+
DiskCache.del(path)
|
31
|
+
DiskCache.get(path).should be_nil
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'disk_cache'
|
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: disk_cache
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Maximilian Haack
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-11-09 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rspec
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
description: A simple way to cache your files.
|
47
|
+
email:
|
48
|
+
- mxhaack@gmail.com
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- .gitignore
|
54
|
+
- .travis.yml
|
55
|
+
- Gemfile
|
56
|
+
- LICENSE.txt
|
57
|
+
- README.md
|
58
|
+
- Rakefile
|
59
|
+
- disk_cache.gemspec
|
60
|
+
- lib/disk_cache.rb
|
61
|
+
- lib/disk_cache/version.rb
|
62
|
+
- spec/asset/Trollface.svg
|
63
|
+
- spec/file_cache/file_cache_spec.rb
|
64
|
+
- spec/spec_helper.rb
|
65
|
+
homepage: ''
|
66
|
+
licenses: []
|
67
|
+
post_install_message:
|
68
|
+
rdoc_options: []
|
69
|
+
require_paths:
|
70
|
+
- lib
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
segments:
|
78
|
+
- 0
|
79
|
+
hash: 804760917571637690
|
80
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
segments:
|
87
|
+
- 0
|
88
|
+
hash: 804760917571637690
|
89
|
+
requirements: []
|
90
|
+
rubyforge_project:
|
91
|
+
rubygems_version: 1.8.24
|
92
|
+
signing_key:
|
93
|
+
specification_version: 3
|
94
|
+
summary: Cache files that you have have to use several times.
|
95
|
+
test_files:
|
96
|
+
- spec/asset/Trollface.svg
|
97
|
+
- spec/file_cache/file_cache_spec.rb
|
98
|
+
- spec/spec_helper.rb
|