Skip to content

Shared cache mechanism for performance via dependency injection #12

Description

@codemeasandwich

When having full control over the application stack. Batching multiple requests into one message, indicates that there is no order dependency on the encapsulated messages. Caching database queries in this scenario is a good optimisation. E.g. DataLoader

I propose adding a .shared mechanism. In the way .stream is exposed

Example

// create as normal
const ChatSchema = new mongoose.schema({ text: String });
const Chat = moduleStream('Chat', ChatSchema);

// create a shared ref
const ChatWithCachedQueries = Chat.shared()

// use shared ref
workTodo({Chat:ChatWithCachedQueries})

function async workTodo(modules){
 // this find call will be Cached, so if the same query is call on this shared module. 
 // It will return the same value instead of hitting the database again
 const chats = await modules.Chat.find({})
 // ... do something with chats
}
// reuse shared ref
workSomeOtherWork({Chat:ChatWithCachedQueries})

Question: What if the DB object is change in App?.. = this change will be reflected to all instances

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions