From a648d55e060dea59540a50c5ba7464f2197acf3a Mon Sep 17 00:00:00 2001 From: Dante Catalfamo Date: Fri, 28 Apr 2023 01:18:06 -0400 Subject: rails-test-cache: Language --- content/posts/testing-rails-cache/index.org | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/content/posts/testing-rails-cache/index.org b/content/posts/testing-rails-cache/index.org index 397eae4..9c98f7f 100644 --- a/content/posts/testing-rails-cache/index.org +++ b/content/posts/testing-rails-cache/index.org @@ -11,11 +11,13 @@ If you're in the default testing environment your rails cache is [[https://api.rubyonrails.org/classes/ActiveSupport/Cache/NullStore.html][=ActiveSupport::Cache::NullStore=]] which will always succeed but it doesn't actually store or return anything. -There's an almost completely undocumented function called -=with_local_cache= that gets implemented on =NullStore= that lets -you run a block with a =MemoryStore= instead of a =NullStore=. This -happens because it =prepends= the -[[https://api.rubyonrails.org/classes/ActiveSupport/Cache/Strategy/LocalCache.html][=ActiveSupport::Cache::Strategy::LocalCache=]] class. +There's an almost completely undocumented method called +=with_local_cache= on =NullStore= that lets you run a block with a +=MemoryStore= instead of a =NullStore= for the duration of the block. +This happens because it =prepends= the +[[https://api.rubyonrails.org/classes/ActiveSupport/Cache/Strategy/LocalCache.html][=ActiveSupport::Cache::Strategy::LocalCache=]] class. This lets you test +one or two things that require caching without enabling it on all +tests and slowing everything down. #+begin_src ruby Rails.cache.class.name -- cgit v1.2.3