Custom Extensions #3
Josh-McFarlin
started this conversation in
Show and tell
Replies: 2 comments 1 reply
-
Here is my s3 cache! https://github.com/DAlperin/dov.dev-remix/blob/main/app/utils/s3imagecache.server.ts This is a more idiomatic version of a thing I hacked together internally that I mentioned in #22 Next up I am going to serve the cached images from cloudfront directly |
Beta Was this translation helpful? Give feedback.
1 reply
-
Thanks so much for this library. Here is mine for GCP import { Bucket, Storage } from '@google-cloud/storage';
class GCPCache extends Cache {
config: CacheConfig;
cache: Bucket;
prefix: string;
constructor() {
super();
let oneYear = 365 * 24 * 60 * 60;
this.config = { ttl: oneYear, tbd: oneYear };
const storage = new Storage({ projectId: 'testId' });
const bucket = storage.bucket('test-bucket-name');
this.cache = bucket;
this.prefix = 'image-cache';
}
async status(key: string): Promise<CacheStatus> {
let [exists] = await this.cache.file(`${this.prefix}/${key}`).exists();
return exists ? CacheStatus.HIT : CacheStatus.MISS;
}
async has(key: string): Promise<boolean> {
let [exists] = await this.cache.file(`${this.prefix}/${key}`).exists();
return exists;
}
async get(key: string): Promise<Uint8Array | null> {
let [buffer] = await this.cache.file(`${this.prefix}/${key}`).download();
return buffer;
}
async set(key: string, resultImg: Uint8Array): Promise<void> {
let createStream = this.cache
.file(`${this.prefix}/${key}`)
.createWriteStream({ metadata: { contentType: 'image/webp' } });
createStream.end(resultImg);
}
async clear(): Promise<void> {
// this.cache.clear();
}
} too lazy to move the bucket and project info to config haha. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Create a new
cache
,resolver
, ortransformer
that you think others would use? Show off your creation here!Beta Was this translation helpful? Give feedback.
All reactions