0

I have a json api where i perform action caching :

class Api::V2::TagsController < Api::V2::BaseController

  before_filter :set_cache_headers, :only => [:categories, :tribes]
  caches_action :categories, :tribes, :expires_in => 1.hour

The only way i found to expire this cache is to use :

Rails.cache.delete api_v2_categories_url(:locale => nil)+'.json?'

This is terribly ugly

Please can anyone help me improve this terrible hack ?


More informations :

Caching works great and i see cache writes in logs :

Cache write: http://localhost:3000/api/v2/categories.json?

In an admin namespace i need to expire the cache, i've tried :

expire_action(:controller => '/api/v2/tags', :action => 'categories', :format => :json)

Which fails and outputs :

Expire fragment views/localhost:3000/mu-8c54ade2-cbb77ba0-4f0c28d3-607169d0.json?action=categories&controller=api/v2/tags&locale=fr

P.S: I've tried this answer without success: rails caching: expire_action in another namespace

Community
  • 1
  • 1
vdaubry
  • 11,369
  • 7
  • 54
  • 76

2 Answers2

0

You could create a new route in your api called clear_categories and in it call

expire_action :action => :categories

Then in your admin just hit that route. You could also redirect back to the calling admin page by passing a redirect url to clear_categories or something to that effect.

Craig Heneveld
  • 389
  • 2
  • 7
0

I had a similar issue and fixed it using something like below,

expire_fragment(ActionCachePath.new(self, {
    :controller => '/api/v2/tags',
    :action => 'categories'
}, true).path)
elimirks
  • 1,452
  • 2
  • 17
  • 30
Matt V
  • 1