2011-09-23 38 views
1

我在Heroku上有一個Sinatra應用程序,我從許多第三方API獲取數據並將其存儲在內存緩存中,以加快加載時間。在Sinatra/memcached應​​用程序中不會過期的緩存數據

但是數據並未更新:啓用插件後第一次加載的數據始終停留在memcache中,並且不會過期。

這裏是我的代碼部分:

set :cache, Dalli:client.new 

configure do 
    set :cache_default_expiry, 300 
end  

def get_apidata() 
    apidata = settings.cache.get('apidata') 
    if apidatadata.nil? 
     # getting data from API 
     settings.cache.set('apidata',apidata) 

哪裏是在我的代碼問題,爲什麼不緩存數據過期?

回答

1

從我的測試set :cache_default_expiry不起作用。你可以做的是這樣的:

set :cache, Dalli::Client.new(ENV['MEMCACHE_SERVERS'], 
          :username => ENV['MEMCACHE_USERNAME'], 
          :password => ENV['MEMCACHE_PASSWORD'], 
          :expires_in => 300) 
相關問題