Using ASP.NET PDF Viewer Control
How to upload, display PDF file, manage cached pdf files in ASP.NET mvc PDF Viewer web control. Free C# open source code.


Free C# open source code to upload pdf file, display pdf from database, and manage cached contents using asp.net mvc pdf viewer control.







What contents are in the EdgePDF cached folder?



There are three groups of content inside the cached folder. All of them are stored in the project folder "/RasterEdge_Cache/".



a. "/_log_files/". There are log files created by SDK. You can delete them at any time. It will not cause any problem. However if you have found any bugs, we need those log files to fix the problems.

b. "/base/". Any documents opened by EdgePDF ASP.NET PDF Viewer web control will create a sub folder under "/base/". Before the user can view a pdf file in web browser, the SDK will convert pdf file to those files which can be supported in web browser, such as svg, html, css, image, web font files.

c. "/ufor/". Any user actions on the files are saved on this folder. One user per folder. User actions includes new added annotations, redactions, pdf page process actions.

About Cache Clean Up
As the running time of the application increases, the stored data in the EdgePDF cache folder will gradually grow, (especially in the File Cache Folder and User Cache Folder). The application should clean up these data regularly to avoid too many server's storage resources are occupied.







How to Select a suitable Clean Up Frequency



EdgePDF has included APIs to manage cached content on the web server. The demo project also includes detailed sample C# source code.

For ASP.NET Core web application, open file /EdgePDF for ASP.NET Core/Program.cs

For ASP.NET Framework web project, open file /EdgePDF Demo Project/Global.asax, and navigate to function TimerTask()



How often to run cache content clean job?

EdgePDF has build-in functions to clean the cached content. You can customize and define how often to run the data clean job.

The following content and C# source code explains how to define the data clean job frenquency.

  1. fileCacheCleanTimer defined a clean job to delete file data in folder /base/, will be run 6 hours after the web application is started, and will run every 6 hours also.
  2. userRequestMinTime defined a clean job to delete web user action data in folder /ufor/, will be run 6 hours after the web application is started, and will run every 6 hours also.



//  Set auto clean task for the upload file cache folder.
//  Clean the cache folder every 6 hours.
IntervalTime fileCacheCleanTimer = new IntervalTime(0, 6, 0);



//  Set auto clean task for the user file request cache folder.
//  Clean the cache folder every 6 hours.
IntervalTime userFileRequestCacheCleanTimer = new IntervalTime(0, 6, 0);


How old data will be cleaned?

You can easily define and apply how old data to be cleaned.

  1. fileLifeMinTime set the minimum life time of each file opened by EdgePDF. The following C# code set the minimum life time is 3 days. Any cached file in folder /base/ which is older than this time will be removed by the clean job.
  2. userRequestMinTime set the minimum life time of each user file request in folder /ufor/. The following C# source code is setting 3 days also.



//  Set the minimum life time of each entry in the cache folder to 3 days. 
IntervalTime fileLifeMinTime = new IntervalTime(3, 0, 0);


//  Set the minimum life time of each entry in the cache folder to 3 days. 
IntervalTime userRequestMinTime = new IntervalTime(3, 0, 0);




The C# source code below shows how to apply the above clean job config settings.



Scheduler.StartCacheCleanTask(CacheCleanType.FileCacheCleanTime,
                              fileCacheCleanTimer, fileLifeMinTime);



Scheduler.StartCacheCleanTask(CacheCleanType.UserFileRequestCacheCleanTime,
                              userFileRequestCacheCleanTimer, userRequestMinTime);