Performance Optimization
Optimize MockMaster for maximum performance.
Scenario Caching
import { readScenario } from '@mockmaster/cli'
import type { Scenario } from '@mockmaster/msw-adapter'
class ScenarioCache {
private cache = new Map<string, Scenario>()
async get(dir: string, name: string): Promise<Scenario> {
const key = `${dir}/${name}`
if (this.cache.has(key)) {
return this.cache.get(key)!
}
const scenario = await readScenario(dir, name)
this.cache.set(key, scenario)
return scenario
}
clear() {
this.cache.clear()
}
}
export const scenarioCache = new ScenarioCache()Parallel Loading
// Sequential - slow
const scenario1 = await readScenario('./scenarios', 'users')
const scenario2 = await readScenario('./scenarios', 'products')
// Parallel - fast
const [scenario1, scenario2] = await Promise.all([
readScenario('./scenarios', 'users'),
readScenario('./scenarios', 'products')
])Complete Examples
See the MASTER_DOCUMENTATION.md for complete performance optimization examples.