Skip to content

Commit 9b948cb

Browse files
committed
Replace GetFileInfo() with faster FileInfo() if using Lucee Fixes #8
1 parent f3aaa7e commit 9b948cb

4 files changed

Lines changed: 22 additions & 8 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 2.1.4 - 9 October 2019
2+
- \#8 Replace GetFileInfo() with faster FileInfo() if using Lucee
3+
14
## 2.1.3 - 8 November 2017
25
- \#7 Handle errors caused by file system being out of sync with file operations cache
36

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2017 Julian Halliwell
3+
Copyright (c) 2013-2019 Julian Halliwell
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy of
66
this software and associated documentation files (the "Software"), to deal in

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ This port is licensed under an MIT license
105105

106106
### The MIT License (MIT)
107107

108-
Copyright (c) 2017 Julian Halliwell
108+
Copyright (c) 2013-2019 Julian Halliwell
109109

110110
Permission is hereby granted, free of charge, to any person obtaining a copy of
111111
this software and associated documentation files (the "Software"), to deal in

adaptiveImages.cfc

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
component{
22

3-
variables.version = "2.1.3";
3+
variables.version = "2.1.3-develop";
4+
variables.isACF = ( server.coldfusion.productname IS "ColdFusion Server" );
5+
variables.isLucee = ( server.coldfusion.productname IS "Lucee" );
46

57
function init(
68
required array resolutions // the resolution break-points to use (screen widths, in pixels, any order you like)
@@ -168,8 +170,8 @@ component{
168170
}
169171

170172
private void function checkCachedImageIsNotLargerThanSource( required string cachedFilePath, required string sourceFilePath ){
171-
cachedFileSize = GetFileInfo( cachedFilePath ).size;
172-
sourceFileSize = GetFileInfo( sourceFilePath ).size;
173+
cachedFileSize = _GetFileInfo( cachedFilePath ).size;
174+
sourceFileSize = _GetFileInfo( sourceFilePath ).size;
173175
if( cachedFileSize GT sourceFileSize ){
174176
_log( "AI: Scaled image is #( cachedFileSize - sourceFileSize )# bytes larger than the original. Copying original instead." );
175177
FileCopy( sourceFilePath, cachedFilePath );
@@ -306,9 +308,9 @@ component{
306308
//This check is expensive: disabled by default, but use if images change frequently and you are not using deleteCachedCopies() when performing updates
307309
private boolean function fileHasBeenUpdated( required string sourceFilePath, required string cachedFilePath ){
308310
// get last modified of cached file
309-
var cacheDate = GetFileInfo( cachedFilePath ).lastModified;
311+
var cacheDate = _GetFileInfo( cachedFilePath ).lastModified;
310312
// get last modified of original
311-
var sourceDate = GetFileInfo( sourceFilePath ).lastModified;
313+
var sourceDate = _GetFileInfo( sourceFilePath ).lastModified;
312314
_log( "AI: Checking for source updates: Cached file modified: #cacheDate#, source file modified: #sourceDate#" );
313315
return ( cacheDate LT sourceDate );
314316
}
@@ -336,7 +338,7 @@ component{
336338
cfheader( name: "Content-type", value: mimeType );
337339
if( IsNumeric( browserCacheSeconds ) )
338340
cfheader( name: "Cache-Control", value: "private,max-age=#browserCacheSeconds#" );
339-
var fileInfo = GetFileInfo( filepath );
341+
var fileInfo = _GetFileInfo( filepath );
340342
cfheader( name: "Content-Length", value: fileInfo.size );
341343
cfcontent( file: filepath, type: mimeType );
342344
abort;
@@ -346,4 +348,13 @@ component{
346348
cfcookie( name: "resolution", value: "deleted", expires: "now" ); //Change value to make testable
347349
}
348350

351+
private struct function _GetFileInfo( required string path ){
352+
if( !isLucee )
353+
return GetFileInfo( arguments.path );
354+
var result = FileInfo( arguments.path );
355+
// support GetFileInfo().lastmodified
356+
result.lastmodified = result.dateLastModified;
357+
return result;
358+
}
359+
349360
}

0 commit comments

Comments
 (0)