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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:09:26+00:00 2026-06-17T09:09:26+00:00

I am trying to use memcached for the first time but I have a

  • 0

I am trying to use memcached for the first time but I have a few questions when it comes to queries with dynamic variables.

This is a sample of my code so far. I got everything working but if you see any mistakes on my code please let me know.

    <cfoutput>
    <cfset variables.memcachedFactory = createObject("component","memcachedfactory").init("127.0.0.1:11211")>
    <cfset variables.memcached = variables.memcachedFactory.getmemcached()>

    <cfset email = "sbcglobal"> //Pretend that this is a list with multiple choices for the user to choose from. 


//The query below would have multiple outputs based on the selection of the user above 
    <cfquery name="test" datasource="#ds#">
        select top 10 * from contact where email like '%#email#%'
    </cfquery>

//Setting the key
    <cfset set100 = variables.memcached.set(key="queryTest2",value=test,expiry="5000")>

//Getting the key
    <Cfset test6 = variables.memcached.get("queryTest2")>

    <br><br>this is the query test - did we retrieve it correctly?  - <br />

    <Cfdump var="#Test6#"><br />

    </cfoutput>

Now, do i have to set a key for every possible outcome of the query? (which in my case would be a few hundred keys to cover all possible outcomes)
My understanding is that memcached saves the value to a key after the first request and after that you get the output without db calls.
If I use memcached in my case would it just be a waste of code since each query would be different based on the user’s choice?

Also, how do you update the values in cache in case the output changes? Is this something that I would have to do manually? My database get 100’s of transactions daily, a select * from contacts at 10 am will not have the same output at 5pm

  • 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-17T09:09:26+00:00Added an answer on June 17, 2026 at 9:09 am

    The idea behind caching (in this case) is that you first check memcached, and if the key exists, you get the data from the cache. If it doesn’t exist, you go to the database, get the data, stick it in memcached, then return it to the user.

    For your use case here, you want a unique key for each unique record set you’re returning. Take your example. If email address is the unique key you are using to identify a record set, then use that as the key in memcached. Pseudo-code:

    <cfset results = variables.memcached.set(key="foo_#email#",value=test,expiry="5000")>
    

    foo_ lets you provide a “namespace” for the keys you are putting into memcached, which makes it easier to manage and avoid key collisions.

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

Sidebar

Related Questions

I'm trying to use memcache for the first time on App Engine and am
I'm trying to use http://www.flexablecoder.com/blog/index.cfm/memcached client. All works ok but for each cfm call,
I'm trying to build 5.6.4-labs-innodb-memcached, but having this issue: # cmake ./ -- MySQL
Im trying use a Java annotation in a Groovy class but have trouble to
I am trying use gem tire to search in my application. I have tables
Hi I'm trying use a datepicker on a field I have. I'm trying to
I am need paint my image. I'm trying use JQuery in here this link:
I'm setting up memcached. I have a couple questions regarding high traffic and best
I'm trying to use Apache::Session::Memcached in an HTML::Mason project where I'm using MasonX::Request::WithApacheSession to
I'm trying to use memcache but I'm stuck on a small part. I've got

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.