Cachify
This is an extract from the Upton parser project. This serves as a drop-in
replacement for all ye download-cache-reading needs.
Installation
Add this line to your application's Gemfile:
gem 'cachify'
And then execute:
$ bundle
Or install it yourself as:
$ gem install cachify
Usage
The primary interface is the Cachify::Downloader
class. This takes three
paramters: a URI, a cache enable/disable option, and a cache location.
options
-
URI: For now, only get
requests work properly since the library
internally uses open-uri
for the fetching part. You can encode the URL
as per your requirement.
-
Cache enable/disable: This takes a truthy or falsy value. True-ish if
you want caching and false-ish if you don't want it.
-
Cache location: This is the cache location. By default, this is set to
Dir.tmpdir/cachify
.
Checks if a cache is present. If not, the cache is created,
the file is downloaded and is saved in the cache and is read.
Cachify::Downloader.new("http://www.example.com").get
Ignores the cache and downloads the url for every call to #get
Cachify::Downloader.new("http://www.example.com", :cache => false).get
Ignores the cache and downloads the url for every call and saves
the cache to the "cache" folder in the same directory
Cachify::Downloader.new("http://www.example.com", :cache => false, :cache_location => "./cache").get
Todo
- #get reads the whole file. Ideally, this should just save the file in
the cache or memory. A #read method should read the file contents.
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request