itrigga-file_cache

A simple file-system-based cache wrapper.

The main method is ‘with_cache( :cache_key=>’something_unique’, :timeout_seconds=>(an integer) ){ (…) }‘ If the given cache key exists and has not timed out, it will return the cached value If not, it will

  • yield to the given block

  • store the result of the given block in the cache with the given key

  • return the result of the given block

Required params:

  • :cache_key=>‘some unique string that is valid in a filename’

Optional params:

  • :timeout_seconds => (an integer - default 3600)

  • :cache_dir => (an absolute path - defaults to RAILS_ROOT/tmp/cache if RAILS_ROOT is defined, otherwise /tmp/cache )

Example usage:

@stats_json = Itrigga::Cache::FileCache.with_cache(:cache_key=>‘admin_stats.json’, :timeout_seconds=>600)

/* some expensive remote API / slow IO call here /*

Contributing to itrigga-file_cache

  • Check out the latest master to make sure the feature hasn’t been implemented or the bug hasn’t been fixed yet

  • Check out the issue tracker to make sure someone already hasn’t requested it and/or contributed it

  • Fork the project

  • Start a feature/bugfix branch

  • Commit and push until you are happy with your contribution

  • Make sure to add tests for it. This is important so I don’t break it in a future version unintentionally.

  • Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.

Copyright © 2011 Al Davidson. See LICENSE.txt for further details.