Friday 15 April 2011

ruby - Handling 304 Not modified in rails Application -



ruby - Handling 304 Not modified in rails Application -

i have couple questions best practice on handling scenario. i'm using 3rd party api access user's resource. have api calls in apiwrapper.rb.

def index response = apiwrapper.get_resource(token, account_id,etag) if response.headers['status'] == "200 ok" @resource = response elsif response.headers['status'] == "304 not modified" @resource = "?????" else redirect_to root_path, notice: "#{response.headers['status']} ju know" end end

the 3rd party requires clients utilize http freshness headers each request. above, checking if etag has changed, if has body of response , store in @resource if hasn't changed i'll 304 in response , response body empty. so, want render resource has been unchanged.

my question pattern this? do utilize caching strategy , typical caching strategy this?

i've looked memcached/dalli i'm nervous security implications i'm not competent on correctly configuring servers , these protected user resources 3rd party account.

do save info model on database?

then, serve current_user.resource.last doesn't improve performance, limits calls enforced api server. additionally, doesn't seem best practice save api calls in way.

can utilize simple rails caching?

something

def index response = apiwrapper.get_resource(token, account_id,etag) if response.headers['status'] == "200 ok" @resource = response # write rails cache store rails.cache.write("#{response["resource_title"]}","response["resource_title"]" ) elsif response.headers['status'] == "304 not modified" # fetch rails cache store @resource = rails.cache.fetch("#{response["resource_title"]}") else redirect_to root_path, notice: "#{response.headers['status']} ju know" end end

this doesn't seem work many users , result in caches beingness stored.

as can see little confused , looking direction here, give thanks you.

ruby-on-rails ruby api http controller

No comments:

Post a Comment