Is the banner rotator tied to the scope instead of the database?

I'm putting together a simple banner rotator system for my coldfusion application, and while I have a pretty clear idea of ​​how to achieve it, I'm more concerned about the actual performance of the solution.

All solutions I've seen on the internet are based on continuous tampering with the underlying database (consisting of pulling recods ids from the database - rolling them over) - displaying the appropriate banner - increasing views / clicks and updating to the database).

Considering my site has one hundred visitors per hour, each visiting 10 pages on average, this means that every month 1000 update database transactions and 1000 updates are updated just to show banner ads, and although read requests can be easily cached updates cannot.

My question is, would copying a request containing all the banners to a new object in the APPLICATION scope be sane aproach? This does not seem to be too obvious, given that you need to (sometimes) synchronize the database also due to the lack of persistence of the scope between possible server reboots.

+3


source to share


1 answer


It's good that you're trying to think outside the box. Sometimes the easiest is not what's best.

As Matt Boucher said, I don't think the weight of 2k requests per hour (2 every 3.6 seconds) is a big concern, but I wanted to focus on what you said in the comment.

Basically, the banner should only update the number of impressions to the left and / or hit / click. The obvious disadvantage of the application domain approach is that the application will need to be restarted every time you add a new banner to the database.

There are several ways to avoid this in CF. I think the most practical (unless you are querying the database directly) is using cfcache.

It is unwise to inform customers that banners will be added "in the next X hours" and use any of the caching methods. CF suggests caching content.

Use <cfcache>



<cfset cache_fresh = false>
<cfcache timespan="#createTimeSpan(0,12,0,0)#" ...> <!--- Timeout set to 12 hours --->
  <cfset cache_fresh = true>
  <cfif StructKeyExists(Application,"BannerObj")>
    object exists, update table.
  </cfif>
  Query table
  Update Application.BannerObj with new data.
</cfcache>

      

#cache_fresh#

is a variable that you can use to see if only this cache was created in this request. This information may be useful to you.

The nice part about cfcache's solution is that you can force the update by clearing the cache if you want to update the system every time a banner was added or had a situation where a banner should have been removed now , for example if it breaks your ToS.

Using an application scope variable.

<cflock name="upbanners" timeout="10">
  <cfif Application.ReGetData is true>
    Query for data and copy to application scope.
    <cfset Application.ReGetData = false>
  </cfif>
</cfif>

      

If the banner system is not updated for several days, the code is never repeated. All you need to update right away is to set ReGetData to true, the next request to the banner system will update the object.

+1


source







All Articles