I would like to create a hit counter for my ColdFusion app. I don't want the database hits table to be updated on each page hit. Ideally, I would like to aggregate the hits in the app scope, or the cache in some type of struct, then save them intermittently.
I have to ideas so far:.
Idea 1
- Create an app or cache struct to store pageId and pageHits key value pair.
- On each page hit, check for the existence of pageId/ip address cookie.
- a. If it exists, do nothing.
- b. If it does not, set it and update the hits struct in the app or cache.
Problem: I don't know how to get the struct data into the database intermittently/after a certain time has elapsed. Scheduled event?
Idea 2
No cookies; save pageId/ip address in their own cache/app struct.
Problem I'm not sure how to structure the data structs/arrays to store the info. Seems complicated with array loops and struct finds. And I still have the same problem as idea one.
Any advice, ideas, criticism? In particular, I need some help figuring out the data structures for idea 2. I'm more interested in performance than data integrity and happy with CF9 only solution. I should add I'm looking to denormalize data into a page hits column for every page id. I don't need normalized data tables.