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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:26:21+00:00 2026-05-23T14:26:21+00:00

I’m working on a method that, due to the expense of it’s operation and

  • 0

I’m working on a method that, due to the expense of it’s operation and frequency which it is called with identical arguments, would benefit from caching the return values.

I’ll be serialize()-ing the arguments together for cache keys, but this can result in very long keys, due to the lengthy array arguments.

  • Does PHP array indexing and look-up suffer from such long keys (think from 250B to 1kB+)?
  • So far so good, but am I facing a situation where this could fail spectacularly on me at some point?
  • Basically, should I md5() (or alternative) the keys?

Minor clarifications:
This is only per-request caching, with no permanent storage. The method in question is that of a view helper, and for each view generation it may be called 500 times or more.

  • 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-23T14:26:21+00:00Added an answer on May 23, 2026 at 2:26 pm

    You should definitely hash the key. You would maybe say “Why should i risk getting collisons when i can concatenate at every point of time a unique key?”. The easy answer is if you generate cache keys via string concatenation you have to calculate always with the worst case of space requirements to estimate ram usage.

    So if you have a cache with 200 entries .. and 2 fields with 20character max strings. The worst case would be 200*2*20*(size of character). If you load the complete cache on every possible parallel connection this will multiply by the amount of parallel connections.

    With hashes you always have the minimum ram requirement = maximum ram requirement for the key field.

    If you have many values which are concatenated for the keys this will scale very bad.

    Edit:

    Even if you use it per request the array consumes memory. Though it is a cache it is present from the beginning to the end of the request. So you need to take into account that it consumes a certain amount of space in your memory and while using a hash its a fixed amount.

    The second thing is that keys need to be compared. If you access an associative array with a string key your interpreter needs to compare the key charwise. If you have a hash method for generating keys this will be also a fixed number of steps.

    If you use concatenation the amount of steps will range between the best and the worst case.

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

Sidebar

Related Questions

I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I've got a string that has curly quotes in it. I'd like to replace

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.