Templates on a Server Farm: CachedFile


The CachedFile IFileObject is used to synchronize XSLT files across a load balanced server farm. This is accomplished in two ways:
  1. Attachments using a CachedFile IFileObject are automatically synchronized each time they are accessed, or every 5 minutes, whichever is less frequent, and
  2. Monitoring the database for ConfigurationEntry rows for file overrides (ConfigurationEntry.Source = 'FileOverride')

Attachments using CachedFile

XSLTs uploaded or edited by power users typically use the 'Template' FileObject by default, and the Template file object should be configured as a CachedFileA sample FileObject.config:

<FileObject Name="AmazonS3" Type="qbo.Attachment.Amazon.S3FileObject, qbo.Attachment.Amazon" Uri="https://mybucket.s3.amazonaws.com"/>
<FileObject Name="Template" Type="qbo.Attachment.FileObjects.CachedFile, qbo.Attachment" Uri="AmazonS3" Compression="false"/>
<FileObject Name="SAN" Type="qbo.Attachment.FileObjects.UNCFile, qbo.Attachment" Uri="//MySan/Share/" Compression="false"/>

The CachedFile IFileObject works as follows:
  • It's URI must match the name of another FileObject (a BaseFileObject) from which attachments will be copied
  • Attachments will be copied to a CacheFolder (c:\windows\temp by default)
    • This can be overridden from Design > Config > Modules > Attachment > Settings, CacheFolder
    • If CacheFolder is empty, then ScratchPad is used instead.  Scratchpad defaults to c:\windows\temp
  • When accessing a file, the CacheFile will look for the file in the CacheFolder
    • If the file is missing, it will be copied from the BaseFileObject
    • If the file is present, but more than CacheDurationMinutes old, it will be re-copied from the BaseFileObject
      • CacheDurationMinutes defaults to 5 minutes, and can be overridden from Design > Config > Modules > Attachment > Settings

File Overrides

XSLTs that are installed with QBO source code deployments may be overridden as follows:
  • Ensure the CacheFolder is set to the root folder of the QBO3 website, and
  • Insert a row into ConfigurationEntry where Source = 'FileOverride'
Inserting rows into ConfigurationEntry can be done via the Import Framework, typically as part of a setup package.  A sample snippet:


Migrating to CachedFile

To migrate a QBO3 installation to use CachedFile, the following steps should be take:
  1. Rename the existing Template file object entry to TemplateOld
  2. Create a new FileObject entry called Template, using CachedFile (as described above)
  3. UPDATE Attachment SET FileObjectAssembly = 'TemplateOld' WHERE FileObjectAssembly = 'Template'
  4. For each Attachment using the TemplateOld FileObject, queue up Attachment/TransferFile?ID=X&FileObject=Template