<commit_before># CachedResource [![Build Status](https://secure.travis-ci.org/Ahsizara/cached_resource.png)](http://travis-ci.org/Ahsizara/cached_resource)
CachedResource is a Ruby gem whose goal is to increase the performance of interacting with web services via ActiveResource by caching responses based on request parameters.  It can help reduce the lag created by making repeated requests across a network.

## Installation
	gem install cached_resource

## Configuration
By default, CachedResource will cache responses to an `ActiveSupport::Cache::MemoryStore` and logs to an `ActiveSupport::BufferedLogger` attached to a `StringIO` object.  **In a Rails 3 environment**, CachedResource will attach itself to the Rails logger and cache. Check out the options section to see how to change these defaults and more.

Enable CachedResource across all ActiveResources.

	class ActiveResource::Base
		cached_resource
	end

Enable CachedResource for a single class.

	class MyActiveResource < ActiveResource::Base
		cached_resource
	end

### Options
CachedResource accepts the following options:

* `:cache` The cache store that CacheResource should use. Default: `ActiveSupport::Cache::MemoryStore`
* `:ttl` The time in seconds until the cache should expire. Default: `604800`
* `:logger` The logger to which CachedResource messages should be written. Default: `ActiveSupport::BufferedLogger`
* `:enabled` Default: `true`

You can change these options when call `cached_resource`

	cached_resource :cache => MyCacheStore.new, :ttl => 60, :logger => MyLogger.new, :enabled => false

You can also change these options on the fly, both globally and on a class-specific basis.  Class specific options take precedence over global options.

Turn CachedResource off.  This will cause all ActiveResource responses to be retrieved normally (i.e. via the network).

	CachedResource.off!
	MyActiveResource.off!

Turn CachedResource on.

	CachedResource.on!
	MyActiveResource.on!

Set the cache expiry time to 60 seconds.

	CachedResource.ttl = 60
	MyActiveResource.ttl = 60

Set a different logger.

	CachedResource.logger = MyLogger.new
	MyActiveResource.logger = MyLogger.new

Set a different cache store.

	CachedResource.cache = MyCacheStore.new
	MyActiveResource.cache = MyCacheStore.new

## Usage
Sit back and relax! If you need to reload a particular request you can do something like:

	MyActiveResource.find(:all, :reload => true)<commit_msg>Update README for configuration changes<commit_after># CachedResource [![Build Status](https://secure.travis-ci.org/Ahsizara/cached_resource.png)](http://travis-ci.org/Ahsizara/cached_resource)
CachedResource is a Ruby gem whose goal is to increase the performance of interacting with web services via ActiveResource by caching responses based on request parameters.  It can help reduce the lag created by making repeated requests across a network.

## Installation
	gem install cached_resource

## Configuration
Enable CachedResource across all ActiveResources.

	class ActiveResource::Base
		cached_resource
	end

Enable CachedResource for a single class.

	class MyActiveResource < ActiveResource::Base
		cached_resource
	end

### Options
CachedResource accepts the following options:

* `:cache` The cache store that CacheResource should use. Default: The `Rails.cache` if available, or an `ActiveSupport::Cache::MemoryStore`
* `:ttl` The time in seconds until the cache should expire. Default: `604800`
* `:logger` The logger to which CachedResource messages should be written. Default: The `Rails.logger` if available, or an `ActiveSupport::BufferedLogger`
* `:enabled` Default: `true`

You can set up CachedResource with these options.

	cached_resource :cache => MyCacheStore.new, :ttl => 60, :logger => MyLogger.new, :enabled => false

You can also change these options on the fly.

Turn CachedResource off.  This will cause all responses to be retrieved normally (i.e. via the network).

	MyActiveResource.cached_resource.off!

Turn CachedResource on.

	MyActiveResource.cached_resource.on!

Set the cache expiry time to 60 seconds.

	MyActiveResource.cached_resource.ttl = 60

Set a different logger.

	MyActiveResource.cached_resource.logger = MyLogger.new

Set a different cache store.

	MyActiveResource.cached_resource.cache = MyCacheStore.new

## Usage
Sit back and relax! If you need to reload a particular request you can do something like this:

	MyActiveResource.find(:all, :reload => true)
{'fraction_non_alphanumeric': 0.07239208633093525, 'fraction_numerical': 0.006070143884892087, 'mean_word_length': 5.187760778859527, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3558594', 'n_tokens_mistral': 1243, 'n_tokens_neox': 1180, 'n_words': 494}