2013-04-25 26 views
0

我有一個JSON API的另一個命名空間在哪裏執行動作緩存:軌道緩存:expire_action在JSON格式

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

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

我發現過期此緩存的唯一方法是使用:

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

這是非常醜陋的

請任何人都可以幫助我改善這種可怕的黑客?


更多信息:

緩存的偉大工程,我看到緩存寫入日誌中:

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

在管理員命名空間,我需要到期緩存中,我已經嘗試過:

expire_action(:contr奧勒> '/ API/V2 /標籤',:動作=> '類別',:格式=>:JSON)

哪個失敗並輸出:

過期片段 視圖/本地主機:3000 /mu-8c54ade2-cbb77ba0-4f0c28d3-607169d0.json?action=categories &控制器= API/V2 /標籤&區域= FR

PS:我試過這個答案沒有成功:rails caching: expire_action in another namespace

回答

0

你可以創建你的API名爲clear_categories一個新的路線,並在其中調用

expire_action :action => :categories 

然後在你的管理員只需點擊這條路線。您也可以通過將重定向網址傳遞給clear_categories或其他相關內容重定向回主叫管理頁面。

0

我也有類似的問題,使用類似下面固定它,

expire_fragment(ActionCachePath.new(self, { 
    :controller => '/api/v2/tags', 
    :action => 'categories' 
}, true).path)