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 1044893
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:54:00+00:00 2026-05-16T15:54:00+00:00

I have a class with this method: def telecom_info Rails.cache.fetch("telecom_info_for_#{ref_num}", :expires_in=> 3.hours) do info

  • 0

I have a class with this method:

def telecom_info

    Rails.cache.fetch("telecom_info_for_#{ref_num}", :expires_in=> 3.hours) do
      info = Hash.new(0)
      Telecom::SERVICES.each do |source|
          results = TelecomUsage.find(:all, 
                                      :joins=>[:telecom_invoice=>{ :person=> :org_person}], 
                                      :conditions=>"dotted_ids like '%#{ref_num}%' and telecom_usages.ruby_type = '#{source}'", 
                                      :select=>"avg(charge) #{source.upcase}_AVG_CHARGE,
                                                max(charge) #{source.upcase}_MAX_CHARGE,
                                                min(charge) #{source.upcase}_MIN_CHARGE,
                                                sum(charge) #{source.upcase}_CHARGE,
    
                                                avg(volume) #{source.upcase}_AVG_VOLUME,
                                                max(volume) #{source.upcase}_MAX_VOLUME,
                                                min(volume) #{source.upcase}_MIN_VOLUME,
                                                sum(volume) #{source.upcase}_VOLUME
                                                ")
    
          results = results.first
          ['charge', 'volume'].each do |source_type|                                        
            info["#{source}_#{source_type}".to_sym] = results.send("#{source}_#{source_type}".downcase).to_i
            info["#{source}_min_#{source_type}".to_sym] = results.send("#{source}_min_#{source_type}".downcase).to_i
            info["#{source}_max_#{source_type}".to_sym] = results.send("#{source}_max_#{source_type}".downcase).to_i
            info["#{source}_avg_#{source_type}".to_sym] = results.send("#{source}_avg_#{source_type}".downcase).to_i
          end
      end
      
      return info
    end
end

As you can see, this is an expensive call, and it is called ALOT for each request so I want to cache it. The problem is that memcached does not seem to work, in the log file, I am getting:

Cache read: telecom_info_for_60000000

Cache miss: telecom_info_for_60000000 ({})

The weird thing is that I know memcached is working since it does cache the results of some other functions I have in another model.

Any suggestions? I am running Rails 2.3.5 on REE 1.8.7

  • 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-16T15:54:01+00:00Added an answer on May 16, 2026 at 3:54 pm

    Replace return info with info.

    Rails.cache.fetch("telecom_info_for_#{ref_num}", :expires_in=> 3.hours) do
      # ...
      info
    end
    

    The return keyword always returns from the current method, which means that info is never returned to your call to Rails.cache.fetch, nor is the rest of that method ever executed. When the last statement simply is info, this is the value that will be given to Rails.cache.fetch, and you will allow the method to finish its duty by storing this value in the cache.

    Compare the following:

    def my_method
      1.upto(3) do |i|
        # Calling return immediately causes Ruby to exit the current method.
        return i
      end
    end
    
    my_method
    #=> 1
    

    As a rule of thumb: always omit return unless you really mean to exit the current block and return from the current method.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this class-level method in an ActiveRecord model class. def self.is_animal_color_correct?(animal, color) if
I have an abstract class with some methods,including an abstract method(Execute()).This method is overridden
I have this method in my db class public function query($queryString) { if (!$this->_connected)
I have written this clone method for when the parent of the Employee class
I have a proxied method in a MongoRepository extender class like this: public interface
In my base class I have a generic method (ideally this would be a
I have a class with a method called DataIn(int InputID, string CSVValue) , this
I have a class extends NamedParameterJdbcDaoSupport. well this superclass has a final setDataSource method
Suppose I have a class in Ruby: class Test def method(arg1, arg2) return arg1+arg2
I have a Python 3 class method for rescaling values that looks like this:

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.