Skip to content

Commit

Permalink
- Cache of pdf pages also consider file size and modification time
Browse files Browse the repository at this point in the history
  • Loading branch information
mauvilsa committed Feb 17, 2021
1 parent 56fb8c4 commit 0c02d79
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

nw-page-editor - Simple app for visual editing of Page XML files.

Version: 2020.12.07
Version: 2021.02.17


# Description
Expand Down
16 changes: 13 additions & 3 deletions js/page-canvas.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Javascript library for viewing and interactive editing of Page XMLs.
*
* @version $Version: 2020.12.07$
* @version $Version: 2021.02.17$
* @author Mauricio Villegas <mauricio_ville@yahoo.com>
* @copyright Copyright(c) 2015-present, Mauricio Villegas <mauricio_ville@yahoo.com>
* @license MIT License
Expand All @@ -23,7 +23,7 @@
'use strict';

var
version = '$Version: 2020.12.07$'.replace(/^\$Version. (.*)\$/,'$1');
version = '$Version: 2021.02.17$'.replace(/^\$Version. (.*)\$/,'$1');

/// Set PageCanvas global object ///
if ( ! global.PageCanvas )
Expand Down Expand Up @@ -225,6 +225,11 @@
canvas.height = imgHeight;
canvas.width = imgWidth;

try {
var fstat = require('fs').statSync(pdfPagePath.replace(/^file:\/\//, '').replace(/\[[0-9]+]$/, ''));
pdfPagePathSize += ':'+fstat.size+':'+fstat.mtimeMs;
} finally {}

page.render({ canvasContext: context, viewport: viewport })
.then( function () {
canvas.toBlob( function(blob) {
Expand Down Expand Up @@ -290,7 +295,12 @@
pageNum = /]$/.test(image.attr('data-rhref')) ? parseInt(image.attr('data-rhref').replace(/.*\[([0-9]+)]$/,'$1'))+1 : 1;

/// Try to get pdf page from cache ///
// @todo Auto clear and update of cache (update if file change date is different, remove cached pages that were stored days ago, remove cached oldes pages to limit cache storage use)

try {
var fstat = require('fs').statSync(url.replace(/^file:\/\//, ''));
pdfPagePathSize += ':'+fstat.size+':'+fstat.mtimeMs;
} finally {}

var request = new Request(pdfPagePathSize.replace(/^file:\/\//,'http://file'));
if ( typeof cached === 'undefined' ) {
caches.match(request).then( response => pdfLoader( image, onLoad, typeof response === 'undefined' ? false : response ) );
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nw-page-editor",
"version": "2020.12.07",
"version": "2021.02.17",
"description": "Simple app for visual editing of Page XML files",
"main": "./html/index.html#1",
"author": "Mauricio Villegas <mauricio_ville@yahoo.com>",
Expand Down
4 changes: 2 additions & 2 deletions web-app/common.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
/**
* Common code to be executed by other php scripts.
*
* @version $Version: 2020.12.07$
* @version $Version: 2021.02.17$
* @author Mauricio Villegas <mauricio_ville@yahoo.com>
* @copyright Copyright(c) 2017-present, Mauricio Villegas <mauricio_ville@yahoo.com>
* @license MIT License
*/

$version = str_replace('Version: ','',"Version: 2020.12.07");
$version = str_replace('Version: ','',"Version: 2021.02.17");
$v = '?v='.$version;

/// User authentication ///
Expand Down

0 comments on commit 0c02d79

Please sign in to comment.