Add bull and caching
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { CACHE_MANAGER } from '@nestjs/cache-manager';
|
||||
import { Cache } from 'cache-manager';
|
||||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { Client, ItemBucketMetadata, UploadedObjectInfo } from 'minio';
|
||||
|
||||
@@ -7,7 +9,10 @@ export class MinioService {
|
||||
private readonly client: Client;
|
||||
public readonly defaultBucketName: string;
|
||||
|
||||
constructor(private readonly configService: ConfigService) {
|
||||
constructor(
|
||||
private readonly configService: ConfigService,
|
||||
@Inject(CACHE_MANAGER) private cacheManager: Cache,
|
||||
) {
|
||||
this.client = new Client({
|
||||
endPoint: this.configService.get<string>('S3_ENDPOINT', 's3.hooli.co'),
|
||||
port: this.configService.get<number>('S3_PORT', 443),
|
||||
@@ -46,6 +51,21 @@ export class MinioService {
|
||||
);
|
||||
}
|
||||
|
||||
public async getCachedBuffer(
|
||||
bucketName: string,
|
||||
objectName: string,
|
||||
cacheTtl: number = 0.1,
|
||||
): Promise<Buffer> {
|
||||
const cacheKey = `${bucketName}/${objectName}`;
|
||||
const cachedValue = await this.cacheManager.get<Buffer>(cacheKey);
|
||||
if (cachedValue) {
|
||||
return Buffer.from(cachedValue);
|
||||
}
|
||||
const object = await this.getBuffer(bucketName, objectName);
|
||||
this.cacheManager.set(cacheKey, object, cacheTtl);
|
||||
return object;
|
||||
}
|
||||
|
||||
public async getBuffer(
|
||||
bucketName: string,
|
||||
objectName: string,
|
||||
|
Reference in New Issue
Block a user