mirror of
https://github.com/tcgdex/javascript-sdk.git
synced 2025-07-29 17:09:50 +00:00
@ -1,26 +1,19 @@
|
||||
// Temporary disable this as it will be rebuilt to make it like the php-sdk one
|
||||
// eslint-disable-next-line max-classes-per-file
|
||||
import TCGdex from './tcgdex'
|
||||
|
||||
export default class RequestWrapper {
|
||||
private static cache: Array<Request<any>> = []
|
||||
|
||||
public static getRequest<T>(url: string) {
|
||||
let req = this.cache.find((req) => req.url === url) as Request<T>|undefined
|
||||
if (!req) {
|
||||
req = new Request<T>(url)
|
||||
this.cache.push(req)
|
||||
}
|
||||
return req
|
||||
}
|
||||
}
|
||||
|
||||
export class Request<T = any> {
|
||||
public static ttl = 1000 * 60 * 60 // 1 hour
|
||||
|
||||
// 1 hour of TTL by default
|
||||
public static ttl = 1000 * 60 * 60
|
||||
|
||||
private response?: T
|
||||
|
||||
private fetched?: Date
|
||||
|
||||
public constructor(
|
||||
public url: string // url is public for quick url test
|
||||
// url is public for quick url test
|
||||
public url: string
|
||||
) {}
|
||||
|
||||
public async get(): Promise<T | undefined> {
|
||||
@ -48,4 +41,20 @@ export class Request<T = any> {
|
||||
this.fetched = now
|
||||
return this.response
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default class RequestWrapper {
|
||||
|
||||
private static cache: Array<Request<any>> = []
|
||||
|
||||
public static getRequest<T>(url: string): Request<T> {
|
||||
let request = this.cache.find((req) => req.url === url) as Request<T>|undefined
|
||||
if (!request) {
|
||||
request = new Request<T>(url)
|
||||
this.cache.push(request)
|
||||
}
|
||||
return request
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user