cache
This commit is contained in:
parent
4bdd60112a
commit
3274381345
@ -47,7 +47,7 @@
|
||||
"hash-sum": "^2.0.0",
|
||||
"human-format": "^1.2.1",
|
||||
"magic-string": "^0.30.15",
|
||||
"murmurhash-native": "^3.5.0",
|
||||
"murmurhash-native": "link:..\\..\\node-murmurhash-native",
|
||||
"pathe": "^1.1.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
4826
packages/domain-expansion/package/pnpm-lock.yaml
Normal file
4826
packages/domain-expansion/package/pnpm-lock.yaml
Normal file
File diff suppressed because it is too large
Load Diff
@ -93,22 +93,9 @@ export function getCurrentContext(): ContextTracking | undefined {
|
||||
|
||||
const assetTrackingSym = Symbol.for('@domain-expansion:astro-asset-tracking');
|
||||
(globalThis as any)[assetTrackingSym] = (original: typeof getImage): typeof getImage => {
|
||||
debug('Wrapping getImage');
|
||||
return (runtime.getImage = async (options) => {
|
||||
const result = await original(options);
|
||||
|
||||
const context = contextTracking.getStore();
|
||||
if (context) {
|
||||
const val: PersistedMetadata['assetServiceCalls'][number] = {
|
||||
options: result.rawOptions,
|
||||
resultingAttributes: result.attributes,
|
||||
};
|
||||
debug('Collected getImage call', val);
|
||||
context.assetServiceCalls.push(val);
|
||||
}
|
||||
|
||||
return result;
|
||||
});
|
||||
debug('Assigning original getImage, skipping wrapper');
|
||||
runtime.getImage = original;
|
||||
return original;
|
||||
};
|
||||
|
||||
export async function computeEntryHash(filePath: string): Promise<string> {
|
||||
|
||||
@ -248,11 +248,16 @@ interface ExtendedSSRResult extends SSRResult {
|
||||
}
|
||||
|
||||
for (const { options, resultingAttributes } of cachedMetadata.assetServiceCalls) {
|
||||
debug('Replaying getImage call', { options });
|
||||
const result = await runtime.getImage(options);
|
||||
try {
|
||||
debug('Replaying getImage call', { options });
|
||||
const result = await runtime.getImage(options);
|
||||
|
||||
if (!isDeepStrictEqual(result.attributes, resultingAttributes)) {
|
||||
debug('Image call mismatch, bailing out of cache');
|
||||
debug('Image call mismatch, bailing out of cache');
|
||||
return null;
|
||||
}
|
||||
} catch (error) {
|
||||
debug('Error replaying getImage call', { options, error });
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -1,9 +0,0 @@
|
||||
catalog:
|
||||
astro: ^5.0.0
|
||||
|
||||
packages:
|
||||
- package
|
||||
- package/tests/fixture/*
|
||||
- packages/*
|
||||
- playground
|
||||
- docs
|
||||
@ -118,7 +118,6 @@ export default async function load(id) {
|
||||
const sources = await Promise.all(
|
||||
widths.map(async (width) => {
|
||||
const hash = getHash(width);
|
||||
|
||||
const assetPath = getAssetPath(
|
||||
base,
|
||||
assetFileNames,
|
||||
@ -128,8 +127,7 @@ export default async function load(id) {
|
||||
);
|
||||
|
||||
if (!store.has(assetPath)) {
|
||||
const config = { width, ...options };
|
||||
|
||||
const config = { width, ...options };
|
||||
// Create cache key for this specific image transformation
|
||||
const cacheKey = {
|
||||
src: id,
|
||||
@ -137,15 +135,13 @@ export default async function load(id) {
|
||||
type,
|
||||
extension,
|
||||
options: objectHash(options)
|
||||
};
|
||||
|
||||
let imageObject = null;
|
||||
|
||||
};
|
||||
let imageObject = null;
|
||||
// Only use cache in production builds
|
||||
if (environment === "production") {
|
||||
if (environment === "build") {
|
||||
imageObject = await get_cached_object(cacheKey, 'imagetools-plugin');
|
||||
if (imageObject) {
|
||||
console.log(`[imagetools-cache] Cache hit for ${assetPath}`);
|
||||
//console.log(`[imagetools-cache] Cache hit for ${assetPath}`);
|
||||
}
|
||||
}
|
||||
|
||||
@ -166,20 +162,18 @@ export default async function load(id) {
|
||||
imageObject = { hash, type, image, buffer };
|
||||
|
||||
// Cache the processed result in production
|
||||
if (environment === "production") {
|
||||
if (environment === "build") {
|
||||
await set_cached_object(cacheKey, 'imagetools-plugin', imageObject, {
|
||||
src: id,
|
||||
width,
|
||||
type,
|
||||
timestamp: Date.now()
|
||||
});
|
||||
console.log(`[imagetools-cache] Cached ${assetPath}`);
|
||||
//console.log(`[imagetools-cache] Cached ${assetPath}`);
|
||||
}
|
||||
}
|
||||
|
||||
store.set(assetPath, imageObject);
|
||||
}
|
||||
|
||||
const modulePath =
|
||||
environment === "dev" ? assetPath : projectBase + assetPath;
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
---
|
||||
import { Img } from "imagetools/components";
|
||||
import { Img, Picture } from "imagetools/components";
|
||||
import Translate from "./i18n.astro"
|
||||
import { translate } from "@/base/i18n";
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user