CTA BusTracker and TrainTracker APIs are rate-limited, so CTA Redux has built-in support for caching API responses. None of the data is refreshed faster than 60 seconds anyways, so there's nothing to lose by caching.

CTA Redux comes out-of-the box configured with an in-process cache that stores all responses for 60 seconds. It is not configurable, but it is enabled by default and will work well for testing or light workloads.

If you plan on using CTA Redux heavily in a production environment, you can configure a more heavy-duty caching solution. Anything that implements the ActiveSupport::Cache interface (specifically responding to #read, #fetch, and #write) will work just fine.

Accessing the internal cache:

[1] pry(main)> require 'cta_redux';
[2] pry(main)> CTA::CustomerAlerts.cache
=> #<SimpleCache:0x007fb53c09f288 @cache={}>

Replacing the cache:

[1] pry(main)> require 'cta_redux';
[2] pry(main)> require 'active_support/cache';
[3] pry(main)> CTA::CustomerAlerts.cache
=> #<SimpleCache:0x007fe274a499e0 @cache={}>
[4] pry(main)> new_cache = ActiveSupport::Cache.lookup_store
=> <#ActiveSupport::Cache::MemoryStore entries=0, size=0, options={}>
[5] pry(main)> CTA::CustomerAlerts.cache = new_cache
=> <#ActiveSupport::Cache::MemoryStore entries=0, size=0, options={}>
[6] pry(main)> CTA::CustomerAlerts.alerts!;
[7] pry(main)> CTA::CustomerAlerts.cache
=> <#ActiveSupport::Cache::MemoryStore entries=1, size=78436, options={}>

It should be noted that while the built-in SimpleCache expires entries after 60 seconds, any other cache store used will not be configured as such. Any setup to expire keys must be set up on the new cache store before configure CTA Redux to use it.

If desired, caching can be disabled altogether. Note that the time returned from the server begins to vary once caching is disabled:

[1] pry(main)> require 'cta_redux';
[2] pry(main)> CTA::BusTracker.key = 'foo';
[3] pry(main)> puts "#{Time.now.to_s} #{CTA::BusTracker.time!.timestamp.to_s}";
2015-02-16 00:15:56 -0600 2015-02-16T00:15:56+00:00
[4] pry(main)> puts "#{Time.now.to_s} #{CTA::BusTracker.time!.timestamp.to_s}";
2015-02-16 00:15:59 -0600 2015-02-16T00:15:56+00:00

[5] pry(main)> CTA::BusTracker.cache_responses = false;
[6] pry(main)> puts "#{Time.now.to_s} #{CTA::BusTracker.time!.timestamp.to_s}";
2015-02-16 00:16:05 -0600 2015-02-16T00:16:05+00:00
[7] pry(main)> puts "#{Time.now.to_s} #{CTA::BusTracker.time!.timestamp.to_s}";
2015-02-16 00:16:06 -0600 2015-02-16T00:16:07+00:00