Skip to content

Commit

Permalink
Merge pull request #41 from sealink/expire_caches
Browse files Browse the repository at this point in the history
Expire caches
  • Loading branch information
alxberardi committed May 19, 2016
2 parents 5434c70 + f644df8 commit 952491b
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 14 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).
This changelog adheres to [Keep a CHANGELOG](http://keepachangelog.com/).

## [2.3.0]

### Changed
- Change cache expiries

## [2.2.2]
### Changed
- Deprecates Booking#calculate_price_quote
Expand Down
2 changes: 2 additions & 0 deletions lib/quick_travel/cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ def self.cache(key, cache_options = {})
cached_value = cache_store.read(key)
return cached_value unless cached_value.nil?
return nil unless block_given?
cache_options ||= {}
cache_options[:expires_in] = 1.day unless cache_options.key?(:expires_in)
yield.tap { |value| cache_store.write(key, value, cache_options) }
end

Expand Down
2 changes: 1 addition & 1 deletion lib/quick_travel/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def sub_resources

def self.all_with_price(opts)
find_all!("/api/resources/index_with_price.json",
opts.merge(cache: "#{name}.all_with_price-attrs"))
opts.merge(cache: "#{name}.all_with_price-attrs?#{opts.to_param}&date=#{Date.current}"))
end

def product_type
Expand Down
4 changes: 1 addition & 3 deletions lib/quick_travel/route.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ def self.all_by_route_ids_and_product_type_id(route_ids, product_type_id)
# All routes for a given product type
def self.all(product_type_id)
find_all!("/product_types/#{product_type_id}/routes.json",
cache: "QuickTravel::Route.all-#{product_type_id}-attrs",
# expires_in will only work with something like Rails.cache
cache_options: { expires_in: 1440.minutes })
cache: "QuickTravel::Route.all-#{product_type_id}-attrs")
end

def self.find(routes_list, route_id)
Expand Down
12 changes: 2 additions & 10 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,14 @@
require 'rspec/its'
require 'date' # Needed for stamp
require 'stamp' # Some reasons stamp doesn't load automatically?
require 'vcr'

ENV['QT_KEYS'] ||= 'test_key_1,test_key_2'
qt_keys = ENV['QT_KEYS'].split(',')
VCR.configure do |c|
c.cassette_library_dir = 'spec/support/cassettes'
c.default_cassette_options = { match_requests_on: [:method, :uri, :body] }
c.filter_sensitive_data('<QT_KEY>') { qt_keys[0] }
c.filter_sensitive_data('<QT_KEY_2>') { qt_keys[1] }
c.hook_into :webmock
end

require 'support/vcr_loader'
require 'support/coverage_loader'
require 'quick_travel' # eager load to ensure coverage correct

require 'quick_travel/config'
qt_keys = ENV['QT_KEYS'].split(',')
QuickTravel.configure do |c|
c.url = 'http://test.qt.sealink.com.au:8080'
c.access_key = qt_keys[0]
Expand Down
12 changes: 12 additions & 0 deletions spec/support/vcr_loader.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
require 'vcr'
require 'webmock/rspec'

qt_keys = ENV['QT_KEYS'].split(',')

VCR.configure do |c|
c.cassette_library_dir = 'spec/support/cassettes'
c.default_cassette_options = { match_requests_on: [:method, :uri, :body] }
c.filter_sensitive_data('<QT_KEY>') { qt_keys[0] }
c.filter_sensitive_data('<QT_KEY_2>') { qt_keys[1] }
c.hook_into :webmock
end

0 comments on commit 952491b

Please sign in to comment.