Wednesday, September 27, 2006

The spec of Legacy_Controller cache mechanism (2)

Legacy's cache mechanism can make plural cache files from one content. Imagine a blog module. A blog writer can find a edit icon and a delete icon on his entry. Administrators may find more privileged control icons. In other words, one entry has plural views. Therefore, XOOPS Cube Legacy has to make each cache.

For that, the controller needs many informations which are identity, a flag indicating whether the current content is ebable to cache, and more. Because Legacy based on XOOPS2 doesn't have means to get such informations from modules, the controller uses Delegate mechanism to exchange of information. What the controller wants to know is the following:

  • Can the controller cache this block?
  • What a file name does the controller save the block cache with?
  • Can the controller cache this page of the module?
  • What a file name does the controller save the module cache with?

The controller asks these questions through Delegate. And, the cache module adds functions with the cache policy to the Delegate. Site owners can tune up their cache policy by exchanging cache modules or adding preload.

What delegates are there?

checkEnableBlockCache()
This delegate checks whether the current URL and the current user is allowed to cache, and what condition the controller does cache with. Legacy uses Legacy_BlockCacheInformation as a special information structure to exchange of information, because the function parameter with primitive variables only is not enough. Modules have many informations to report to the controller, and need the special class or structure to easy exchange of information.

Through the delegate, Delegate functions can set a special cache policy to the information structure. I'll explain about it at next time.

getBlockCacheFilePath()
This delegate is used to get a file path of $cacheInfo to save. This is meaning that user functions can interfere in the controller to decide unique file name by their policy.
checkEnableModuleCache()
This is the block version of checkEnableBlockCache(), which use Legacy_BlockCacheInformation as an information structure.
getModuleCacheFilePath()
This is the block version of checkEnableBlockCache().

These delegates are empty basically, so site owners should add delegate functions through the cache module. In other words, if any functions aren't added to these delegates, XOOPS Cube Legacy can't work its cache mechanism.

No comments: