-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
A few feature requests
- An internal cache
- A TTL per resource (even per request?)
- updating, should check if resource has been updated
This can all be condensed into using a repository as an intermediary between the model and any application logic. By using predefined Repository<TModel> we can seperate the model (DBAL) and the Caching functinoality from each other (seperation of concerns).
@Cache({TimeToLive: 500})
class TasksRepository extends Repository<Task> { }With an implementation in a component being
class class ExampleComponent implements OnInit {
public tasks: Task[];
constructor(private taskRepository: TaskRepository){
this.tasks = this.taskRepository.all();
}
public async getSpecificTaskOnHover(id: number) : Task{
return this.taskRepository.find(t => t.id == id);
}
public async refreshTasksOnClick(){
this.tasks = this.taskRepository.forceRefresh();
}
public async updateSpecifiTaskTitle(id: number, newTitle: string){
let task = this.taskRepository.findById(id); // alternative to find(expression)
task.title = newTitle;
this.taskRepository.update(task);
}
public async forceRefresh(){
this.tasks = this.taskRepository.forceRefresh().all();
/// or: this.tasks = this.taskRepository.all({forceRefresh: true});
}
}This should make apps more snappy using this package. Maybe related to #13
This usage of the repository pattern would allow for a few things
- Seperation of concerns with regard to saving, updating etc
- the ability to allow for caching and a TTL per model even per part of the application (repository instance specific config)
- Unit Of Work
- Allow syncing with the database every
xseconds with a full refresh force available per repository
and a general sense of wellbeing :)
Metadata
Metadata
Assignees
Labels
No labels