简体   繁体   中英

How can I stop rails from caching partials from outside rails app or clear the cache with a task

I have a rails application that displays content that is being rendered as a partial, which lives outside my rails app, but on the same web server.

This all displays fine, however the point of this was to allow someone else to push up the content to this folder without needing to reboot the rails application. Deploying and displaying is fine, however the content is cached, and so it still will not update until the servers are rebooted. I tried creating a fragment around the call to the partial and creating a rake task to delete it when the content is deployed:

In my view:

    <% cache("frag_key") do %>
      <%= render :partial => "#{@content_path}.rhtml" %> 
    <% end %>

Rake Task

    namespace :cache do
      desc 'Clear memcache'
      task :clear => :environment do
        Rails.cache.delete('frag_key')
      end
    end

Is there any way to stop the caching of these particular files? Should my solution theoretically work and I am doing something wrong? Any help is appreciated.

Edit: I should also note I am not using memcache.

your solution is not going to work. if you want to really render the file you need to restart the app or disable caching wich will slow down your app a lot.

what you can do is simply treating the partial as an external file and read it from disc with the standard IO operations. if you need to execute some rails code or have access to application specifics, this approach is not going to work.

i remember having read something about storing view-code in the database in josé valims excelent book "Crafting Rails Applications". maybe this gives you some ideas of how you could find a proper solution to your problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM