fragment-caching

Rails 5.2.1 - Model & Fragment Caching

和自甴很熟 提交于 2021-01-29 09:23:20
问题 I am trying to setup Model and Fragment Caching in Rails 5.2.1 I have had success with Fragment caching, but I am still seeing database queries after implementing model caching for my Model. I have enabled development caching $ rails dev:cache Model Helper module LanguagesHelper def approved_languages Rails.cache.fetch("approved_languages") { Languages.is_active.is_approved } end end Controller class LanguagesController < ApplicationController include LanguagesHelper def index @languages =

rails4 after caching query still runs

折月煮酒 提交于 2019-12-12 04:15:55
问题 I have a rails 4 app and trying to implement caching. I use the @profiles_sidebar.first cache key for checking if new user was created. I'm not sure if this is ok, since there still is a db query. Is this the preferred mechanism to check if caching needs to be expired? Am I doing well? <% cache(@profiles_sidebar.first) do %> <% @profiles_sidebar.each do |profile| %> <%= link_to user_path(profile.user) do %> <%= truncate(profile.full_name, length: 25) %> <%= truncate(profile.company, length:25

rails 4 cache expiration not working

北城以北 提交于 2019-12-11 13:50:07
问题 In my rails app I'm trying to use nested caches, but my cache-key is not expiring when user.profile.full_name is changed. So when user changes his/her name the full_name displayed by _profile_product.html.erb remains the old one. How should I change the key? profiles/show.html.erb <% cache(@profile) do %> #this is the profile info and the cache key expires properly when @profile.full_name changes <%= @profile.full_name %> ..... <% end %> <% if @profile.user.products.any? %> #not nested in the

rails4 caching naming conventions

那年仲夏 提交于 2019-12-11 12:46:53
问题 I have a rails 4 app. I have to differentiate the different cache keys somehow but don't know the naming conventions. FIRST EXAMPLE: I have a task model with index , completed_tasks and incoming_tasks actions. A have the same instance name ( @tasks ) though because of the pagination. At the moment the cache-keys are named like below. My questions: 1. Is the cache-key structure good enough? 2. Is it important in which order I put the parts of the key in the array? For example [@tasks.map(&:id)

rails4 double nested models russian-doll-caching

非 Y 不嫁゛ 提交于 2019-12-11 10:21:58
问题 I have the following structure in my rails4 app for the posts. Users can comment on the post and replies can be written on the comments. I'd like to use russian-doll-caching with auto-expiring keys on the page, but I don't know how I should exactly do it in this case. Can sby tell me how to use it in this case? Models: #post.rb belongs_to :user has_many :post_comments, dependent: :destroy #post_comments.rb belongs_to :user belongs_to :post has_many :post_comment_replies, dependent: :destroy

Caching a Drupal site with session-specific data on every page

时光毁灭记忆、已成空白 提交于 2019-12-06 06:50:17
问题 We have a site written in Drupal 6. We want to use Drupal's caching mechanism to improve performance, but when we turned it on, we found problems because our site has session data displayed on every page. Drupal's caching system only works for static content page, and our session data effectively means that none of our pages are static. We've come up with two solutions to this: Rewrite the block that shows the session data such that it loads the non-static data using Ajax, so that the main

Caching a Drupal site with session-specific data on every page

随声附和 提交于 2019-12-04 15:05:30
We have a site written in Drupal 6. We want to use Drupal's caching mechanism to improve performance, but when we turned it on, we found problems because our site has session data displayed on every page. Drupal's caching system only works for static content page, and our session data effectively means that none of our pages are static. We've come up with two solutions to this: Rewrite the block that shows the session data such that it loads the non-static data using Ajax, so that the main HTML content is then static. The down-sides of this are that it will mean quite a lot of work, and also

Optimize APC Caching

…衆ロ難τιáo~ 提交于 2019-12-03 02:02:51
问题 here is a link to how my APC is running : [removed] As you can see, it fills up pretty quickly and my Cache Full Count goes over 1000 sometimes My website uses Wordpress. I notice that every time I make a new post or edit a post, 2 things happen. 1) APC Memory "USED" resets 2) I get a whole lot of Fragments I've tried giving more Memory to APC (512 mb) but then it crashes sometimes, it seems 384 is best. I also have a Cron job that restarts apache, clearing all APC of fragments and used

Optimize APC Caching

吃可爱长大的小学妹 提交于 2019-12-02 17:11:29
here is a link to how my APC is running : [removed] As you can see, it fills up pretty quickly and my Cache Full Count goes over 1000 sometimes My website uses Wordpress. I notice that every time I make a new post or edit a post, 2 things happen. 1) APC Memory "USED" resets 2) I get a whole lot of Fragments I've tried giving more Memory to APC (512 mb) but then it crashes sometimes, it seems 384 is best. I also have a Cron job that restarts apache, clearing all APC of fragments and used memory, every 4 hours. Again, my apache crashes if APC is running for a long period of time, I think due to

rails leaving out some parts from fragment caching

爱⌒轻易说出口 提交于 2019-11-29 16:02:28
I have a rails 4 app using pundit gem for authorization. If I do russian-doll fragment caching like the code below, the conditional statement used for authorization will be also cached, which is not good, since edit/delete buttons should only be available for the post.user . What is the good way to get around this? Should I split the cache into smaller parts or is there a way to exclude some parts of the caching? What's the rails convention in this case? index.html.erb <% cache ["posts-index", @posts.map(&:id), @posts.map(&:updated_at).max, @posts.map {|post| post.user.profile.updated_at}.max]