ES6 Classes & Constructors
What design pattern is demonstrated here?
class Database {
async query(sql) {
console.log(`Executing: ${sql}`);
// Database logic here
return [];
}
}
class DatabaseProxy {
constructor(database) {
this.database = database;
this.cache = new Map();
}
async query(sql) {
if (this.cache.has(sql)) {
console.log('Cache hit');
return this.cache.get(sql);
}
const result = await this.database.query(sql);
this.cache.set(sql, result);
return result;
}
}