This site will look much better in a browser that supports web standards, but it is accessible to any browser or Internet device.

SmartBee Framework : SmartyInteligentCache

How it's works?

An overview

My idea is bulid the ideal cache. I thing the ideal cache should:

  • always return newest data
  • never return old data or secure data
  • cache database results ad recognite when database output was changed
  • support for dynamic data (time, mottos etc.)
  • low processor overhead

Basic Principles

How cache returns actual data?

There is many ways how to do this, but only one way is 100% reliable. Reliable way is to check database output, changes in application code and generate some checksum (MD5). It's not hard to implement this because Smart separate Application Logic and Presentation Layer. When you want to check if something have beeen changed you can easily serialize data at presentation layer and get MD5 checksum.

In bechmarks I fount this:

  • Database (MySQL) output is fast and can be cached (at DB layer!)
  • Application logic is fast and can be cached, but it's too hard to realize
  • Presentation layer is very slow and can be easily cache, when you create checksum of application and DB layer

In fact it's really easy to build ideal cache when you usa Smarty, because all assigned data to templates can be returned by this command: Get_Template_Vars. This function return an array and now we use nice function serialize to get an string. Now we have an string, but it can have 100 kbyt of values, because it can make an processor overhead an filesystem problem we have to make some checksum (MD5). Now we can easily use this checksum as Smarty Cache ID and save every output to difference file.

If you have very dynamic blok - e.c. timestamp, you can use an {dynamic} mark to insert dynamic value. But remember, dynamic block can be associated only from Smarty plug-in, not from application logic. But this is not disadvantage because you can easily create your own Smarty plug-in.