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

  • Home
  • SEARCH
  • 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 8528895
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:54:18+00:00 2026-06-11T08:54:18+00:00

I have created a method that takes in a string value, matches it with

  • 0

I have created a method that takes in a string value, matches it with the user records and returns the matching user’s record.

My code:

class UsersPeer extends BaseUsersPeer
{
  public static function getHashUser($hash)
  {
    $c = new Criteria();
    $c->add(UsersPeer::HASH,$hash);
    return UsersPeer::doSelectOne($c);
  }
}

Does it make sense to cache this function?

My understanding says that since the string value passed to the function shall always be different for different users, the function shall execute each time. However, it shall not execute again for the users, for whom the string value has previously been passed to the method and record retrieved. Only in such cases the function caching shall work.

Given that there are approximately 50K users, does it make any sense enabling caching for this method ?

  • 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-06-11T08:54:19+00:00Added an answer on June 11, 2026 at 8:54 am

    This is a very simple query that should be fast even if the hash column is not indexed (and very fast if it is) – I see no reason to cache the results.

    Result cache is often used in situations where the query is complex, contains aggregate data or subqueries. Even then you should work on the query first to see if you can optimize it.

    Update:

    If you check out the sfCache class (the base for all concrete cache implementations) you’ll see that anything you store in a cache has a lifetime, meaning it gets stored only for a limited time. This means the size of the cache is limited.

    Cache works like this:

    • your function gets called
    • you calculate a cache key from the function name and the parameters
    • ask the cache if there’s a stored value with the given key
    • if yes, you fetch it and return
    • you calculate the return value
    • you store it in the cache then return it

    Whether it’s worth caching a function’s return value is always up to performace measurement. Is it a long-running, computation-intensive function? Is it a performance bottleneck? If your answers are positive, it’s probably worth enabling caching.

    Also remember, that every time you do function caching it increases the amount (and complexity) of code you have to maintain.

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

Sidebar

Related Questions

I have created a gem that adds a new method to the class ActiveRecord::Base.
Currently I have created a ABCFactory class that has a single method creating ABC
I was testing a String multiplier class with a multiply() method that takes 2
I have created code which takes a string from a text field and calls
I have an action method that takes in a string as its only parameter.
I have C function that takes string pointer as a parameter. This functions returns
I have created a method that should ideally take a single Account object and
I have created a custom method that will return unique items, together with the
I have created a new method in one of the project's controllers that it
I have a method that contains the following (Java) code: doSomeThings(); doSomeOtherThings(); doSomeThings() creates

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.