Subscribe: The No-Dans Club
Added By: Feedage Forager Feedage Grade B rated
Language: English
android  application  build  cache  cards  code  date  emulator  install  nativescript  node  package json  project  time  tns  warn 
Rate this Feed
Rate this feedRate this feedRate this feedRate this feedRate this feed
Rate this feed 1 starRate this feed 2 starRate this feed 3 starRate this feed 4 starRate this feed 5 star

Comments (0)

Feed Details and Statistics Feed Statistics
Preview: The No-Dans Club

The No-Dans Club

ColdFusion, Flex, Ajax and other items of interest

Published: Thu, 26 Apr 2018 13:46:39 -0400

Last Build Date: Mon, 23 Oct 2017 07:17:00 -0400


What is a Partner – Part 1

Mon, 23 Oct 2017 07:17:00 -0400

If you remember, I spent 17 years building software, running a startup, and also running a consultancy. Imagine my surprise when I entered the corporate world after a 12-year hiatus.

Apparently, the industry has redefined what the word "Partner" means. Due to my role, I get many emails, offers to connect on Linked In, and other unsolicited communications to "Partner" with another company. Their definition of Partner is for me to get out my checkbook and pay them to do something.

I know I'm not one of the "cool kids" any longer. I'm middle-aged, a parent and I've got a couple of grey hairs. (Queue Grandpa Simpson Voice) However, back in my day that used to be called a Vendor relationship. A partner used to imply something a bit more meaningful.

If you "contact" me with a desire to "partner", please be upfront of how we are partnering. Your proposal should be a bit more meaningful than asking for check for a product or service. If we entered that sort of relationship, I am your customer or client, not your "partner".

DirectTV Fraud 888-407-2674

Wed, 19 Oct 2016 10:36:00 -0400

I've been contacted by a company claiming to be from Direct TV. They claim I can take advantage of a promotion with Amazon to pay 5 months of my bill with an Amazon Gift Card. If I do that, I'll get 2 years at a very reduced rate. I've been stringing these guys along for a few days now, just to see how this works and how I can report it. Since I am not sure how best to shut this down, I'm putting the information on this website. Hopefully it shows up when you google the number or something else. No reputable company would ask you to do this. Further, always google the company and call the phone numbers listed on their site, not some weird number you get from a weird guy on the phone.
  • Company Caller ID: Mas Tec
  • Originating Number: 800-531-5000
  • Promotion Code: CXDTV6266
  • Number to Call: 888-407-2674
  • Identifying characteristics of caller: Indian accents
So if you end up on this web page, and suspect this is happening to you, it's fraud and you should not buy any gift cards. I would expect as this scam evolves, the gift card vendor will change from Amazon.... in short, Gift cards are the same as cash, so never pay weird bills over the phone with them. If you need the billing phone number for Direct TV, call: 1 (800) 531-5000 and get through the phone tree for billing (Ask for representative). This is not a knock on Indian people, nor on Direct TV. Both are awesome.

Why is my connection to Google, Gmail or HSTS Site Untrusted?

Sun, 14 Feb 2016 10:20:00 -0400

Connection to Google untrusted? Fix below! Lately, I have had issues connecting to Google, Google Mail and other random services over the last few months. I did some digging today and fixed (I believe) the issue. If you are having problems with security messages like the below, try these steps to see if it fixes the problem. I'll put some narrative/background info below if you are curious as to my findings. Here's an example of what I would see if I dug into the Untrusted Message: How in the world is accuweather the actual cert for google? Solution: Here's what I did. In short, you need to remove the offending certificates. Your browser will re-ask for them and get the right ones Google Chrome: (screen shots below) Click on the 3 horizontal lined Hamburger menu Click on Advanced Settings Click on HTTPS/SSL Manage Certificates Click on Untrusted Certificates Tab Remove all that said Fraudulent Mozilla Firefox (screen shots below) Click on the 3 horizontal lined Hamburger menu Click on the Options button Click on the Advanced Menu on the right Click on the Certificates Tab Click on the View Certificates Button Click on the Servers Tab and remove the expired certificates Google Chrome Screenshots Mozilla Firefox Screenshots Ok, so what is this all about? From my research, certain sites using HSTS (HTTP Strict Transport Security) are throwing security alerts upon connection to pages on the domain. In March 2011 an HTTPS/TLS Certificate Authority (CA) was tricked into issuing fraudulent certificates. Patches to the major web browsers blacklisted a number of TLS certificates that were issued after hackers broke into the Certificate Authority. These were high value certs and likely state sponsored cyber-attacks from Iran. Below is the list of domains affected: global trustee The weird thing about this, is my computer wasn't even manufactured in 2011. I purchased it in 2013! There must have been a recent update to either the servers matching the domains above, or to my browsers or operating system a few months ago. Regardless, connecting to the domains in the above list has been problematic with random security warnings and even blockages on my own computer. Let me know if this fixed the problem for you! Update: 11/21/2016 This problem has never really gone away. In fact, it drives me nuts! I did find some other things to do to help this go away.... try these steps if you are on windows: From the Control Panel, open network and sharing center On the left side- click on "Change advanced sharing settings" Click on home or work Check "turn off" for the first three questions. Depending on the specifics you may also have to turn on password [...]

NativeScript button event not firing

Wed, 25 Nov 2015 16:41:00 -0400

I spent a bit of time trying to understand why a tap event failed to fire on a button in NativeScript. Here was the original code segments:

Button Code

Updating from NativeScript 1.4 to NativeScript 1.5

Tue, 24 Nov 2015 14:05:00 -0400

I ran into an issue updating NativeScript 1.4 to NativeScript 1.5. The symptom:

> nativescript@1.5.0 postinstall C:\Users\DanWilson\AppData\Roaming\npm\node_modules\nativescript > node postinstall

Basically, after uninstalling and reinstalling NativeScript on Windows 7 (maybe other OS's are affected also), the process would hang at the node postinstall. By hang, I mean it was stuck at the above status for 15 minutes. I looked at the source for postinstall and nothing specifically stood out to me as potentially the problem. Hat tip to Jen Looper for the suggestion to upgrade Node. Upgrading to the latest 4.x fixed the issue for me.

Why were you running an out of date Node DAN?

The NativeScript Getting Started Documentation stipulated Node .12 at the time. Since NativeScript has been released, they have updated the documentation to now include Node 4.x.

It is possible a fresh install might work on .12 or an older version of Node, however once I updated to the latest Node Binaries, the install for NativeScript 1.5 finished promptly. If you have issues upgrading to NativeScript 1.5, freshen up your Node version and that should take care of it.

Application Upgrade

Another thing I noticed, was a difference in the values in the root package.json for the value "tns-core-modules" was 1.4.0. I manually changed that value to 1.5.0 and the application built and deployed successfully. I'm not sure if you HAVE to do that, but I did it and saw no ill effect.

Before manually changing tns-core-modules

Before I manually changed the value of tns-core-modules, I ran npm install to ensure my dependencies were set correctly. Here is what happened:

C:\_web\NativeScript\TradeOMatic>npm install npm WARN package.json @ No description npm WARN package.json @ No repository field. npm WARN package.json @ No README data npm WARN package.json @ No license field.

After manually changing tns-core-modules

C:\_web\NativeScript\TradeOMatic>npm install npm WARN package.json @ No description npm WARN package.json @ No repository field. npm WARN package.json @ No README data npm WARN package.json @ No license field. tns-core-modules@1.5.0 node_modules\tns-core-modules

As you can see from the final line, the tns-core-modules for my specific project were updated to the 1.5.0 version.

The best way to develop and run NativeScript projects in an emulator

Tue, 24 Nov 2015 09:52:00 -0400

I develop NativeScript on Windows. As in most new, shiny technology, developing on Windows has it's quirks. In this post, we'll talk about 3 different ways to run your NativeScript project in an emulator, as well as the pros and cons of each method. I'm also going to use the Android platform. The iOS commands are the same, except for swapping iOS for the keyword android in the command. All methods assume you have an emulator for your platform, with a device profile created. Additionally, at least on Android, it is necessary to start the device emulator you wish to target using the Android Virtual Device Manager, or some other mechanism. Basic: tns run android --emulator Run this command every time you want to push the latest version of your code to the emulator. Pros: You get to see any console output. This means you can debug your application using console.log("foo") statements and see the output. You will stay up to date on your facebook feeds. See Cons below for explanation. Cons: The console logs are VERY chatty. There are heaps of measurement logging and other things not immediately relevant to the application. The sheer amount of logs, can make it hard to find your output. You'll pay a 2 minute tax, at least, waiting on the emulator to get your changes. Change a single character and use this method again? Then you'll pay the 2 minute tax again. (I'm using an SSD laptop with 16GB of RAM.) Because of the latency between updates, I am painfully reminded of my poor typing skills. If this was the only option to write Native mobile applications, I'd probably decide it wasn't for me and go do something else. Tip: At this stage, I can not see a single positive reason to use tns run android --emulator that can't be achieved with one of the below options. In short, you probably don't want to use the workflow tns run android --emulator. As a stretch, perhaps you need to see the Native logs, like all of the measurement logging. Right now I don't need that, so this method is pointless and masochistic. Interactive: tns livesync android --emulator --watch This process watches for source code changes and will automatically build and push the latest version of your code to the emulator. Pros: The time between making a source code change, and seeing the effect of the change in the emulator, is WAY faster than tns run android --emulator. This is somewhat comparable to running a browser based application. I prefer this method when I'm working on layouts, visual changes, or light work inside view-models. Did I mention how fast changes are propagated? If there is an error, you will get a stack trace on your emulator screen. As of NativeScript 1.5, you will see console.log() outputs in your terminal window. YAY! Cons: You get NO console output. All console.log() statements are /dev/null'd.This is no longer true as of {N} 1.5. Console.log() output is streamed to the terminal, without the chattiness of the above method. Tip: If you want more options with how to deal with non-visual logging in NativeScript, write a custom TraceWriter and push the output you want into a frame of your application, or send it over an API or whatever. You can find out more here: tracing-nativescript-applications. Just search for Writing a Custom TraceWriter for an example of your options. Genymotion: tns debug android --geny "Google Nexus 4 - 5.1.0 - API 22 - 768x1280" --debug-brk This process watches for source code changes and will automatically build and push the latest version of your code to the emulator and start a debugging session in Google Chrome. Pros: Changes are propagated quickly, much like tns livesync android --emulator --watch You have introspection, breakpoint and other tools using Google Developer Tools. From my informal testing, the time to complete the initial build and show the app on the screen is less with Genymotion, than it is with the tns livesync android --emulator --watch [...]

TNS Build Android Hangs

Tue, 24 Nov 2015 09:15:00 -0400

Occasionally, while running a NativeScript application on android, the process hangs and does not complete. I have not gotten to the bottom of this, but I can tell you how I resolve the issue to continue running my application.

Symptoms - one of these

C:\_web\NativeScript\TradeOMatic>tns livesync android --emulator --watch Project successfully prepared The application with id "org.nativescript.TradeOMatic" is not installed on the device yet. Project successfully prepared C:\_web\NativeScript\TradeOMatic>tns build android Project successfully prepared

In the above cases, the behavior is the terminal is stuck at the Project successfully prepared status and does nothing. I can watch which binaries are in control of the process, and on Windows, it gets stuck on find.exe.

If the tns livesync android --emulator --watch command hangs, I usually just run tns build android. Usually, this kicks off the build process. If it doesn't, I'll run tns build android again. This almost always works.

If, for some reason, no combination of the commands executed the build process. I remove the Android specific platform processes, then added them again. Example:

C:\_web\NativeScript\TradeOMatic>tns platform remove android C:\_web\NativeScript\TradeOMatic>tns platform add android

When the build process runs, you will see a lot of console output. Example:

Project successfully prepared execute: copyAarDependencies, addAarDependencies before configuration :preBuild UP-TO-DATE :preDebugBuild UP-TO-DATE :checkDebugManifest :preReleaseBuild UP-TO-DATE :prepareComAndroidSupportAppcompatV72311Library UP-TO-DATE :prepareComAndroidSupportSupportV42311Library UP-TO-DATE :prepareDebugDependencies :compileDebugAidl UP-TO-DATE :compileDebugRenderscript UP-TO-DATE :generateDebugBuildConfig UP-TO-DATE :deleteJavaDir UP-TO-DATE :cleanLocalAarFiles UP-TO-DATE :collectAllJars UP-TO-DATE :ensureMetadataOutDir UP-TO-DATE

Then the changes made to the application are ready for deployment. You can use your favorite emulator command to push the build. I prefer tns livesync android --emulator --watch because changes are picked up and deployed automatically, significantly reducing the amount of time needed to validate each change on the emulator.

What happens when you choose the wrong Datatype for an Identifier Column

Wed, 18 Nov 2015 14:01:00 -0400

Choosing database column data types can be dicey. Choose an overly large data type, and indexes will be overly large, storage will fill up and other bad things can happen. Choose an overly small one, and you end up with hard errors. A common data type for a database identity column is an int. However, if your application gets popular, it can break. Pastebin is a victim of it's own success :) (image)

How to fix a Node package error when installing NativeScript

Thu, 12 Nov 2015 09:26:00 -0400

NativeScript is a free open source offering from Telerik allowing mobile development in Javascript with 100% Access to Native Platform APIs in iOS, Android and Windows Phone. With NativeScript, the entire native platform functionality is available in the JavaScript layer. I've finally found the packaging and tooling I want to use to develop native applications in iOS and Android, while using a single language. I develop in Windows and I love it for my daily work. However, occasionally, using Node on windows is a bit more complicated than on other platforms. While following the very comprehensive Getting started guide for NativeScript, I ran in to a sticky issue. Here is the issue and resolution in case it helps you, my weary web traveler friend. Firstly, the root cause of the error was my fault. Even though the Getting Started Guide stated I needed to install "The latest Node 0.10.x or 0.12.x stable official release", I went off-script and installed Node 4.x. Surely this would work, right? After spending a fair amount of time struggling with the CLI command to install NativeScript, I re-read the install docs and figured out my Node version was not the right version, so I uninstalled Node 4.x and installed Node 0.12.x. After running the installer again, I still ran into issues. Part of the issue was the C++ compiler not being available. The standard way to get a C++ compiler is to install Visual Studio, though through research, I found Microsoft is offering a standalone C++ compiler specifically to help out with node. This comment by Sara Itani, discusses the new compiler, how it was tested and has the links to download what you need. I applaud the new and improved Microsoft for their work to support the more modern development platforms like Node. Once I had the compiler installed, I hit another error. This error was caused because the earlier version of Node 4.x left some paths out there that no longer resolved. Once I fixed the paths in the \nodejs\nodevars.bat, and ensured they pointed to the current install of Node 0.12.x, I was able to complete the install. Below is an example of the NativeScript install script output before the error. [C:\Users\DanWilson]npm i -g nativescript npm WARN excluding symbolic link docs\stylesheets\hightlight.css -> ../../node_m odules/highlight/src/styles/solarized_light.css npm WARN excluding symbolic link docs\assets\ir_black.css -> ../../node_modules/ highlight/src/styles/ir_black.css npm WARN excluding symbolic link docs\stylesheets\hightlight.css -> ../../node_m odules/highlight/src/styles/solarized_light.css npm WARN engine xmlbuilder@2.2.1: wanted: {"node":"0.8.x || 0.10.x"} (current: { "node":"0.12.7","npm":"2.11.3"}) | > utf-8-validate@1.0.1 install C:\Users\DanWilson\AppData\Roaming\npm\node_modul es\nativescript\node_modules\utf-8-validate > node ./build `win32-ia32-v8-3.28` exists; testing Binary is fine; exiting npm WARN excluding symbolic link examples\TestFramework\Test Framework.framework \Resources -> Versions/Current/Resources npm WARN excluding symbolic link examples\TestFramework\Test Framework.framework \Test Framework -> Versions/Current/Test Framework npm WARN excluding symbolic link examples\TestFramework\Test Framework.framework \Versions\Current -> A npm WARN excluding symbolic link docs\stylesheets\hightlight.css -> ../../node_m odules/highlight/src/styles/solarized_light.css > bufferutil@1.0.1 install C:\Users\DanWilson\AppData\Roaming\npm\node_modules\n ativescript\node_modules\bufferutil > node ./build `win32-ia32-v8-3.28` exists; testing Binary is fine; exiting > fibers@1.0.6 install C:\Users\DanWilson\AppData\Roaming\npm\node_modules\nativ escript\node_modules\fibers > node build || nodejs build `win32-ia32-v8-3.28` exists; testing Binary is fine; exiting - > ref@1.1.3 install C:\Users\DanWilson\AppData\Roaming\np[...]

I backed a Standing Desk Kick Starter

Fri, 22 May 2015 05:50:00 -0400

Kickstarter is all the rage, isn't it? As the owner of 3 small businesses, I really like the capabilities kickstarter brings to the table. The ability to fund a project based on merit alone, rather than create and shop a business plan to the venture capital industry, makes a ton of sense. My only complaint is I didn't come up with kickstarter and make it my business before they did.

I've been working from home for 9 years. I find myself to be much more productive when I'm in control of my environment. Coffee is made the way I want, when I want it. I can turn my music up to help me blast through mundane tasks. I can have complete quiet when I need it.

I have had this nagging feeling over the last few years that my desk/chair setup isn't what I need. I have a very hard time maintaining correct posture in a chair. When I need to concentrate, I often sit in very uncomfortable postures that cause pain.

Yeah, so what does this have to do with Kickstarter?

My friend Dan Skaggs turned me on to a kickstarter project that is offering to make a high quality motorized standing desk. I decided it's just what I needed. What I need is a way to get a standing desk the EXACT height I need for a comfortable work environment, and also a way to return the desk to a sitting position when I want.

Also, if I decide standing desks aren't what I need, I can keep it at a sitting height. So no fear of commitment, right?

The project is over the original $50,000 goal by a long shot, so others feel the same way as I do. If everything goes well, I'll have a standing desk shipped to my house by July. It'll take a few weeks for me to get adjusted to working in a standing fashion, but I have some fairly reasonable hopes that if I stand for a portion of the day, I'll be able to solve my bad-posture-under-concentration problem to a reasonable degree.

The Project

Take a look at World's First Smart, Connected Office Desk -- Powered By AI.. They have a smart option, with a phone app, and a regular option without all the electronic whiz, bang capabilities. I chose the regular option because I didn't see the need for all the bells and whistles, when I'm just getting started. After reading more about the capabilities, I may be starting to regret my decision. I am now 50%/50% the smart option would be worth the money for my specific purposes.

I also ordered mine without the table top. I have an idea to make a very cool, custom wood top. For now, I can use glass desk top I have now.

Really, in a nutshell, I'm out $348 for a motorized standing desk (with no top) shipped to my house. That's a pretty good deal and is a lot more cost effective than the other standing desks out there that often cost over $1,000.

Once I get the desk, set it up and work through my initial growing pains, I'll post on my thoughts.

ColdFusion 11 - MySQL no Suitable Driver

Mon, 18 May 2015 06:11:00 -0400

For reasons too complicated to get into, ColdFusion 11 no longer ships with a JDBC driver for MySQL. This is a change over previous versions of ColdFusion. Largely, this is because of a license issue relating to redistributing the Jar file.

How to fix it

The fix is easy:

  1. download the JDBC driver JDBC Driver for MySQL (Connector/J) here:
  2. in the Platform select box, choose platform independent
  3. next, choose the tar or zip version appropriate for your platform. If you don't know which to pick, choose the zip version.
  4. next, on the screen titled "Begin Your Download -", scroll to the bottom and choose the small link "No thanks, just start my download."
  5. finally, once the download completes, extract "mysql-connector-java-5.1.35-bin.jar" and put it in the lib directory of your CF install. For me it is located at: C:\ColdFusion11\cfusion\lib (your platform and coldfusion edition impacts the path for you.
  6. restart ColdFusion and validate your datasource in the ColdFusion Administrator.

That's all there is too it!

Presentation Files - Our application got popular and now it breaks!

Thu, 14 May 2015 12:38:00 -0400

I've just posted the presentation "Our application got popular and now it breaks!" that was delivered at Dev.Objective() 15. If you were at the conference and would like the presentation files, you can find a PDF version here. You can also view this presentation on Slideshare

So you helped build a cool application and the public is flooding your site with traffic. What's that smell? Is a server on fire? Oh No! If only you'd thought more about the performance implications of some of your decisions, things would be better. Now, the phones ring at 4AM with angry customers, rousing you out of bed. There isn't enough coffee in the world to get you through these disastrous weeks ahead. You could have avoided all of this by coming to this session.

Bullet Points:

  • Simple design decisions that come back to bite you
  • How to use infrastructure for fun and profit
  • Making the data tier work for you
  • Performance traps and how to get out of them
  • How to be sure your application can handle popularity
  • The audience should have a working knowledge of server programming

The Top 5 Things You are Doing Today to Hinder Scalability

Wed, 22 Oct 2014 11:07:00 -0400

At the CFSummit 2014, I presented on The Top 5 Things You are Doing Today to Hinder Scalability. I collected my material through helping clients to scale their applications over a number of years. The important things in this presentation are listed in order. Decisions you make in your applications today, affect what options you have when you need to scale your application. Certainly it is a very good thing to have an application you built grow to the point you need to consider scalability. Popularity is good, right? However, there are decisions you can make in your code, code architecture and infrastructure architecture that will add or remove scalability options. The presentation was well received by the audience and I thank each and every one of them for choosing to spend their time with me during this time slot. For brevity, I included a number of details in an appendix to the presentation. Review this if you want to know particulars about a specific topic. You can review the slide deck here: I'm always available for questions or consulting, should you need extra help. I hope you enjoyed the CFSummit 2014. See you next year!

Using MongoDB Aggregation Framework to Filter Trello Cards

Tue, 23 Jul 2013 09:14:00 -0400

I'm helping prepare the CFSummit conference. We've organized the sessions on Trello and had a public voting session. It's time to start organizing the topics into a schedule. In a conference schedule, it's important to know which sessions will be popular. It's desirable to ensure the most desirable sessions do not compete with each other. Thus, I wanted to pull out the sessions and organize the sessions by popularity. The MongoDB Aggregation Framework The MongoDB aggregation framework is a relatively new addition to the platform. Using this framework, you can group, sort, calculate and handle information gathering in the aggregate sense. Here's how I did this for the Trello Json data. The Mongo Query Exporting out of Trello gives a big JSON document with JSON members for each card. It turns out, in our case, all of the cards we want belong to a specific list. Once we pull the correct cards, we want to sort them by their votes. We'll end up with a sorted array of sessions by popularity. Here is the MongoDB query: db.cfsummit.aggregate([ {$project: { "cards": "$cards"}}, {$unwind: "$cards"}, {$match: {"cards.idList": {"$in": ["51c9aa15d0b4871a3e000075"]}}}, {$project: {"_id": 1, "name": "$", "members": "$cards.idMembers", "url": "$cards.url", "votes": "$cards.badges.votes"}}, {$sort: {votes:-1}} ]) Explained Line by Line: db.cfsummit.aggregate([ Notice the argument to the aggregate command is an array? This means you can organize a series of document transformations into steps. Each step will manipulate the document in some fashion. Let's look at our first step in the transformation: {$project: { "cards": "$cards"}}, The first transformation is a $project command. Project (Pro-JECT), means to project a new way to view the data. In this case, I'm only interested in the cards node. The result of this document is a new document with basically only the cards member. You can write queries without $project, but I always do use it for 2 reasons. Firstly, reducing the size of the working document makes the query more efficient. The resulting projected document is smaller and can more easily be manipulated. The second reasons is I write my queries incrementally, so I only need to see, what I need to see. (Note the cards member is an array, this is important in the next step) "result" : [ { "_id" : ObjectId("51ee98afaa17829291af81e0"), "cards" : [ { "id" : "51b0fbec94b2237145005a18", "badges" : { "votes" : 0, "viewingMemberVoted" : false, "subscribed" : false, ..... {$unwind: "$cards"}, Now the card nodes is an array. I'm going to want to sort all of the matching cards by the votes parameter. I use an $unwind command to transform the cards array members into their own documents. "result" : [ { "_id" : ObjectId("51ee98afaa17829291af81e0"), "cards" : { "id" : "51b0fbec94b2237145005a18", "badges" : { "votes" : 0, "viewingMemberVoted" : false, "subscribed" : false, ... Note, the cards member is no longer an array... this is important for grouping, which we will do later. {$match: {"cards.idList": {"$in": ["51c9aa15d0b4871a3e000075"]}}} Each of the cards we want to deal with belongs to listId: 51c9aa15d0b4871a3e000075. So we use the $match command to match the cards with the listId we are looking for. (Think of this like a where clause in SQL, if that is your background. "result" : [ { "_id" : ObjectId("51ee98afaa17829291af81e0"), "cards" : { "id" : "51b0fbec94b2237145005a18", "badges" : { "votes" : 0, "viewingMemberVoted" : false, "subscribed" : false, ... {$project: {"_id": 1, "name": "$", "members": "$cards.idMembers", "url": "$cards.url", "votes": "$cards.b[...]

Caching for Fun and Profit: Or why would you ever cache a page for 5 seconds?

Sat, 21 Jul 2012 10:12:00 -0400

There are a lot of ways to cache data. You can cache a piece of data, a query, a page fragment, an entire page, or an entire website. You can cache to local memory, local file storage, distributed memory, distributed file storage, a front cache, or a Content Delivery Network (CDN). You can cache for ever, until the process regenerates, 5 years, 5 months, 5 days, 5 hours or 5 minutes. Heck, it might even, depending on the system, make sense to cache something for 5 seconds. Maybe less. Why would I cache something for 5 seconds? I know, I know, it seems silly to cache something for 5 seconds. You probably think this is a silly attempt at a ridiculous headline to grab clicks. However, let's explore. To get much benefit from caching, cache the content longer than the service time. The service time is the total amount of time it takes to service the request and return the desired item. As an example, if a piece of content takes 5 seconds to generate, the service time is 5 seconds. To get any real benefit, we should cache the content for longer than 5 seconds. What happens if the service time is longer than the cache time? If the service time is longer than the cache time, requests for the piece of content will queue. With caching, we want to AVOID queuing, so it's important to know the service time of the call under a variety of circumstances. You mathematical types can read up on Little's law, if you are curious: A practical example Now, most cachable content has a service time of less than 5 seconds. Let's talk about what would happen in 2 identical systems. To make things simple, we'll pretend the following: There is only one process The service time of the process is 1 second The request levels are 1, 5, 15 and 30 requests per second. The non-cached system is real time, the cached system is cached for 5 seconds In the non-cached system, here's how the requests per second (RPS) would look during 1 traffic hour: 3,600 @ 1 RPS 18,000 @ 5 RPS 54,000 @ 15 RPS 108,000 @ 30 RPS WOW! I bet we'd have some major problems in a real time system under these conditions. Let's compare with the system using a 5 second cache: 720 @ 1 RPS 720 @ 5 RPS 720 @ 15 RPS 720 @ 30 RPS Hmm, that looks odd. The requests in the 1 hour period never get over 720. Seems like an insurance policy against load. Let's look at the amount of requests we save at each of the levels: 3,600-720=2,880 @ 1 RPS 18,000-720=17,280 @ 5 RPS 54,000-720=53,280 @ 15 RPS 108,000-720=107,280 @ 30 RPS Wow! By caching for 5 seconds, we saved between 2,800 = 107,280 requests per hour. What's more interesting we can see we established a service ceiling for our system. We'll never generate more than 720 requests an hour. No matter how many times the link goes viral on As traffic rates increase, the value from a 5 second cache also increases. In a world full of email blasts, viral links, email, IM, social media, we see more and more bursts of traffic. As traffic bursts, we approach the natural threshold of a system. A system can only go as fast as the slowest part, ( so we need to make sure the slowest part is good enough for what business problem we are trying to solve. So should we cache everything at 5 seconds? A 5 second cache isn't the answer to every problem though. Some content can't be cached at all. Like a shopping cart. Some content can be cached forever, like static content (named with a version number). Some content types do not seem cachable, but maybe could possibly be. An example would be a page listing inventory. Perhaps the business is ab[...]