Easy way to begin support 304 status, so on ther side if data was not changed You will load it from local cache. Of course, other side must support Of course, other side must support 304 status also.
At the very begonning you have to include this middleware to Her
# config/initilizers/her.rb
...
Her::API.new.setup do |connection|
...
connection.use Her::Middleware::CacheUnmodified
end
Here is Rails controller example with this support:
class Post < ApplicationController
before_action :check_changes
private
def check_changes
return unless request.headers['HTTP_IF_MODIFIED_SINCE']
return if request.headers['HTTP_IF_MODIFIED_SINCE'].to_datetime > resource.updated_at
render body: nil, status: 304
end
end
Feel free to update is as you like
Add this line to your application's Gemfile:
gem 'her_cache_unmodified'
And then execute:
$ bundle
Or install it yourself as:
$ gem install her_cache_unmodified
Contribution directions go here.
The gem is available as open source under the terms of the MIT License.