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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T14:32:54+00:00 2026-05-10T14:32:54+00:00

Been going over my predecessor’s code and see usage of the request scope frequently.

  • 0

Been going over my predecessor’s code and see usage of the ‘request’ scope frequently. What is the appropriate usage of this scope?

  • 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. 2026-05-10T14:32:55+00:00Added an answer on May 10, 2026 at 2:32 pm

    There are several scopes that are available to any portion of your code: Session, Client, Cookie, Application, and Request. Some are inadvisable to use in certain ways (i.e. using Request or Application scope inside your Custom Tags or CFC’s; this is coupling, violates encapsulation principles, and is considered a bad practice), and some have special purposes: Cookie is persisted on the client machine as physical cookies, and Session scoped variables are user-specific and expire with the user’s session on the website.

    If a variable is extremely unlikely to change (constant for all intents and purposes) and can simply be initialized on application startup and never written again, generally you should put it into Application scope because this persists it between every user and every session. When properly implemented it is written once and read N times.

    A proper implementation of Application variables in Application.cfm might look like this:

    <cfif not structKeyExists(application, 'dsn')>     <cflock scope='application' type='exclusive' timeout='30'>         <cfif not structKeyExists(application, 'dsn')>             <cfset application.dsn = 'MyDSN' />             <cfset foo = 'bar' />             <cfset x = 5 />         </cfif>     </cflock> </cfif> 

    Note that the existence of the variable in the application scope is checked before and after the lock, so that if two users create a race condition at application startup, only one of them will end up setting the application variables.

    The benefit of this approach is that it won’t constantly refresh these stored variables on every request, wasting the user’s time and the server’s processing cycles. The trade-off is that it is a little verbose and complex.

    This was greatly simplified with the addition of Application.cfc. Now, you can specify which variables are created on application startup and don’t have to worry about locking and checking for existence and all of that fun stuff:

    <cfcomponent>     <cfset this.name = 'myApplicationName' />      <cffunction name='onApplicationStart' returnType='boolean' output='false'>         <cfset application.dsn = 'MyDSN' />         <cfset foo = 'bar' />         <cfset x = 5 />         <cfreturn true />     </cffunction> </cfcomponent> 

    For more information on Application.cfc including all of the various special functions available and every little detail about what and how to use it, I recommend this post on Raymond Camden’s blog.

    To summarize, request scope is available everywhere in your code, but that doesn’t necessarily make it ‘right’ to use it everywhere. Chances are that your predecessor was using it to break encapsulation, and that can be cumbersome to refactor out. You may be best off leaving it as-is, but understanding which scope is the best tool for the job will definitely make your future code better.

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

Sidebar

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.