Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7693375
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:04:27+00:00 2026-05-31T21:04:27+00:00

I’d like to use 2 caches — the in memory default one and a

  • 0

I’d like to use 2 caches — the in memory default one and a memcache one, though abstractly it shouldn’t matter (I think) which two.

The in memory default one is where I want to load small and rarely changing data. I’ve been using the memory one to date. I keep a bunch of ‘domain data’ type stuff from the database in there, I also have some small data from external sources that I refresh every 15 min – 1 hour.

I recently added memcache because I’m now serving up some larger assets. Sort of complex how I got into this, but these are larger ~kilobytes, relatively small in quantity (hundreds), and highly cacheable — they change, but a refresh once per hour is probably too much. This set might grow, but it’s shared across all hosts. Refreshes are expensive.

The first set of data has been using the default memory cache for a while now, and has been well-behaved. Memcache is perfect for the second set of data.

I’ve tuned memcache, and it’s working great for the second set of data. The problem is that because of my existing code that was done ‘thinking’ it was in local memory, I’m doing several trips to memcache per request, which is increasing my latency.

So, I want to use 2 caches. Thoughts?

(note: memcache is running on different machine(s) than my server. Even if I ran it locally, I have a fleet of hosts so it wouldn’t be local to all. Also, I want to avoid needing to just get bigger machines. Even though I probably could solve this problem by making the memory bigger and just using the in memory (the data really isn’t that big), this doesn’t solve the problem as I scale, so it will just be kicking the can.)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T21:04:28+00:00Added an answer on May 31, 2026 at 9:04 pm

    ActiveSupport::Cache::MemoryStore is what you want to use. Rails.cache uses either MemoryStore, FileStore or in my case DalliStore 🙂

    You can have global instance of ActiveSupport::Cache::MemoryStore and use it or create a class with a singleton pattern that holds this object (cleaner). Set Rails.cache to the other cache store and use this singleton for MemoryStore

    Below is this class:

    module Caching
      class MemoryCache
          include Singleton
    
          # create a private instance of MemoryStore
          def initialize
            @memory_store = ActiveSupport::Cache::MemoryStore.new
          end
    
          # this will allow our MemoryCache to be called just like Rails.cache
          # every method passed to it will be passed to our MemoryStore
          def method_missing(m, *args, &block)
            @memory_store.send(m, *args, &block)
          end
      end
    end
    

    This is how to use it:

    Caching::MemoryCache.instance.write("foo", "bar")
    => true
    Caching::MemoryCache.instance.read("foo")
    => "bar"
    Caching::MemoryCache.instance.clear
    => 0
    Caching::MemoryCache.instance.read("foo")
    => nil
    Caching::MemoryCache.instance.write("foo1", "bar1")
    => true
    Caching::MemoryCache.instance.write("foo2", "bar2")
    => true
    Caching::MemoryCache.instance.read_multi("foo1", "foo2")
    => {"foo1"=>"bar1", "foo2"=>"bar2"}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I would like to run a str_replace or preg_replace which looks for certain words
I used javascript for loading a picture on my website depending on which small
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I've got a string that has curly quotes in it. I'd like to replace
I am reading a book about Javascript and jQuery and using one of the
I am trying to render a haml file in a javascript response like so:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.