What is DynamicPDF WebCache?
DynamicPDF WebCache, in simple terms, is a file cache management system for PDF documents. DynamicPDF WebCache facilitates the automatic saving and retrieving of the PDF files from a dynamically determined location on the server (outside of the web root) and the automatic clean up of those cached files (at user specified intervals). With WebCache, developers can now have direct access to these cached files without ever needing to know the files exact location on the file system.
DynamicPDF WebCache is designed to work in Web Applications where you would want to save a PDF for a specified period of time and you want to have the ability to easily retrieve those files (immediately or at a later time). A GUI configuration utility is also available to configure all the WebCache settings. If PDF files need to be sent directly to the end user's browser without needing to save a temp file on disk, WebCache does not need to be used. For sending documents directly to a user's browser, the Document's (or MergeDocument's) DrawToWeb method will achieve this.
Why Use DynamicPDF WebCache?
There are many reasons to use DynamicPDF WebCache. Here are a few of them:
- Simple To Use
- Save PDF documents on disk without needing to handle folder structures
- Retrieve files from the file system just as easy
- PDF documents are automatically removed at specified intervals
- Secure
- Complex naming tokens are used making it impossible for hackers to try and guess naming conventions
- Files are saved outside of the web root to further remove any security risks
- Improves PDF creation abilities over SSL connections
- PDF documents can be sent to the user's browser while still taking advantage of linearization (fast web view)
- Eliminates the need to implement complex file and folder naming conventions
How does DynamicPDF WebCache work?
DynamicPDF WebCache consists of three parts:
- An ISAPI filter - this runs on the web site and maps the cached file to the requested URL
- A Local Service - this runs on the server and handles the scheduled clean up (deletion) of the files
- A Configuration Utility - this allows the user to change the caching settings
Once DynamicPDF WebCache is installed on a server, a PDF can be created using DynamicPDF Generator, Merger, ReportWriter or Converter and can be saved through DynamicPDF WebCache (see the example below for source code details). Saving the PDF document using DynamicPDF WebCache will allow you to access that file at a later time.
NOTE: When setting up a new website the "Location" specified in the "New Website" dialog box should be set to "HTTP" not "File System". Since websites with a "Location" set to "File System" do not go through IIS, the WebCache ISAPI filter will not be applied.
DynamicPDF WebCache Service
The purpose of the DynamicPDF WebCache Service is to periodically clean up the files in the cache. It will be an NT service and must be running in order to clean the cache. The service can be stopped and started, but not paused. When the service starts it immediately performs a clean up of the cache. It then performs a cleanup at the Cleanup Interval. A cleanup is performed by checking the names of the folders in the cache. Any folder that was not created between the current time and the current time minus the cache period should have all its files deleted and then the folder itself should be deleted. If any files are locked, that file can be left for the next cleanup cycle.
DynamicPDF WebCache Configuration Utility
By default all setting are changed using the Configuration Utility (C:\Program Files\ceTe Software\DynamicPDF WebCache v1.0\DynamicPDF.WebCache.Config.exe). There are only three settings associated with DynamicPDF WebCache. The settings are as follows:
- Base Path: This is the base file path that will be used when storing the cached PDF (default is C:\DynamicPDF_WebCache).
- Cache Period: This is the shortest time in which any file will be cached for (default is 10 hours or 36,000 seconds).
- Cleanup Interval: This is the interval at which the cache will check for files that need to be deleted (default is 15 minutes or 900 seconds).
It is recommended that the Cleanup Interval be relatively smaller than the Cache Period. Also, any changes to the values in the configuration utility require a restart of IIS in order for those changes to take affect.
DynamicPDF WebCache Installation
In most cases installing DynamicPDF WebCache will be done by running the installer package (the MSI) on the server that you would like the WebCache functionality to be running on. Both the ISAPI filter and the service are set up and started when the installer package (the MSI) is run. During the installation, you will select the specific web site(s) to install the ISAPI filter on.
For steps on how to perform manual installation click here.
Integration with other DynamicPDF Products
DynamicPDF WebCache seamlessly integrates with all DynamicPDF .NET products. Any DynamicPDF Document object has a DrawToWebCache method that is used to save the PDF in the setup WebCache. This DrawToWebCache method returns a WebCacheItem object and the Redirect method of the WebCacheItem class can output the PDF to the browser. The Redirect() method maps to the URL where the PDF file gets stored in the cache. The WebCacheItem returned from the DrawToWebCache object also contains a FilePath property that should be used whenever a direct file path to the PDF is needed. For example this FilePath property would be used if you wanted to attach a cached PDF to a dynamically created email. Click here for an example.