Thus far I've helped install two of the largest ColdFusion-based content management systems for two different clients, and in comparing both one thing is evident: they both just love structs.
In fact, even when a database query returns, say, information about the current site (name, domain, url, etc.), in both systems that information is quickly transfered to a struct and it, not the query, is cached.
Why? Glad you asked:
- Structs are relatively lightweight containers, whereas queries tend to be quite a bit larger and are much more resource intensive.
- Caching a query might entail maintaining an open connection to your database, reducing the number of connections it can handle.
- Lookups and existence checks are faster than doing query-on-query searches, providing fast random-access to key/value pairs.
- A cached query may count as one of your CF Administrator "cached queries". A struct doesn't.
- Structs can hold more stucts, arrays, and other complex data types, allowing data to be nested and presented in a logical fashion.
- Values can easily be altered, changed, and updated as needed.
- Substitution into the HTML is quick and easy. Just do #request.page.title# and you're done.
- With one assignment you can transfer a large amount of cached data into the current request scope for immediate access. No need to individually set two dozen variables by hand each and every time.
- They're easy to dump and examine for debugging and development.
Comments