OpenProject is the leading open source project management software.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
openproject/lib/api/caching/helpers.rb

27 lines
654 B

module API
module Caching
module Helpers
def with_etag!(key)
etag = %(W/"#{::Digest::SHA1.hexdigest(key.to_s)}")
error!('Not Modified'.freeze, 304) if headers['If-None-Match'.freeze] == etag
header 'ETag'.freeze, etag
end
##
# Store a represented object in its JSON representation
def cache(key, args = {})
# Save serialization since we're only dealing with strings here
args[:raw] = true
json = Rails.cache.fetch(key, args) {
result = yield
result.to_json
}
::API::Caching::StoredRepresenter.new json
end
end
end
end