2025-01-13 23:18:10 +02:00
|
|
|
import type FAttribute from "../entities/fattribute.js";
|
2024-07-25 20:36:15 +03:00
|
|
|
|
2020-05-02 18:19:41 +02:00
|
|
|
/**
|
2023-05-05 23:41:11 +02:00
|
|
|
* The purpose of this class is to cache the list of attributes for notes.
|
2020-05-02 18:19:41 +02:00
|
|
|
*
|
2023-05-05 23:41:11 +02:00
|
|
|
* Cache invalidation granularity is global - whenever a write operation is detected to notes, branches or attributes,
|
2020-05-02 18:19:41 +02:00
|
|
|
* we invalidate the whole cache. That's OK, since the purpose for this is to speed up batch read-only operations, such
|
|
|
|
* as loading the tree which uses attributes heavily.
|
|
|
|
*/
|
|
|
|
class NoteAttributeCache {
|
2024-07-25 20:36:15 +03:00
|
|
|
attributes: Record<string, FAttribute[]>;
|
2025-01-09 18:07:02 +02:00
|
|
|
|
2020-05-02 18:19:41 +02:00
|
|
|
constructor() {
|
|
|
|
this.attributes = {};
|
|
|
|
}
|
|
|
|
|
|
|
|
invalidate() {
|
|
|
|
this.attributes = {};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const noteAttributeCache = new NoteAttributeCache();
|
|
|
|
|
2023-05-05 23:41:11 +02:00
|
|
|
export default noteAttributeCache;
|