lib/storyblok/client.rb in storyblok-1.0.4 vs lib/storyblok/client.rb in storyblok-2.0.0
- old
+ new
@@ -13,11 +13,12 @@
api_url: 'api.storyblok.com',
api_version: 1,
logger: false,
log_level: Logger::INFO,
version: 'draft',
- cache_version: Time.now.to_i
+ cache_version: Time.now.to_i,
+ cache: nil,
}
attr_reader :configuration, :logger
# @param [Hash] given_configuration
@@ -90,28 +91,27 @@
def get(request)
endpoint = base_url + request.url
query = request_query(request.query)
query_string = build_nested_query(query)
- if Cache.client.nil?
+ if cache.nil?
result = run_request(endpoint, query_string)
else
- version = Cache.client.get('storyblok:' + configuration[:token] + ':version') || '0'
+ version = cache.get('storyblok:' + configuration[:token] + ':version') || '0'
cache_key = 'storyblok:' + configuration[:token] + ':v:' + version + ':' + request.url + ':' + Base64.encode64(query_string)
- cache_time = 60 * 60 * 2
- result = Cache.cache(cache_key, cache_time) do
+ result = cache.cache(cache_key) do
run_request(endpoint, query_string)
end
end
JSON.parse(result)
end
def flush
- if !Cache.client.nil?
- Cache.client.set('storyblok:' + configuration[:token] + ':version', Time.now.to_i.to_s)
+ unless cache.nil?
+ cache.set('storyblok:' + configuration[:token] + ':version', Time.now.to_i.to_s)
end
end
private
@@ -135,9 +135,13 @@
"http#{configuration[:secure] ? 's' : ''}://#{configuration[:api_url]}/v#{configuration[:api_version]}"
end
def default_configuration
DEFAULT_CONFIGURATION.dup
+ end
+
+ def cache
+ configuration[:cache]
end
def setup_logger
@logger = configuration[:logger]
logger.level = configuration[:log_level] if logger