-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
906 additions
and
5,450 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,3 +63,5 @@ _site | |
|
||
# other junk | ||
.DS_Store | ||
example/**/package-lock.json | ||
example/**/.lazyimages.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
const fs = require('fs'); | ||
|
||
// A global to store the cache data in memory | ||
let lazyImagesCache = {}; | ||
|
||
// Loads the cache data into memory | ||
exports.load = (cacheFile) => { | ||
if (!cacheFile) { | ||
return; | ||
} | ||
|
||
try { | ||
if (fs.existsSync(cacheFile)) { | ||
const cachedData = fs.readFileSync(cacheFile, 'utf8'); | ||
lazyImagesCache = JSON.parse(cachedData); | ||
} | ||
} catch (e) { | ||
console.error('LazyImages - cacheFile', e); | ||
} | ||
}; | ||
|
||
// Reads the cached data for an image | ||
exports.read = (imageSrc) => { | ||
if (imageSrc in lazyImagesCache) { | ||
return lazyImagesCache[imageSrc]; | ||
} | ||
|
||
return undefined; | ||
}; | ||
|
||
// Updates image data in the cache | ||
exports.update = (cacheFile, imageSrc, imageData) => { | ||
lazyImagesCache[imageSrc] = imageData; | ||
|
||
if (cacheFile) { | ||
const cacheData = JSON.stringify(lazyImagesCache); | ||
|
||
fs.writeFile(cacheFile, cacheData, (err) => { | ||
if (err) { | ||
console.error('LazyImages - cacheFile', e); | ||
} | ||
}); | ||
} | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.