Comments (1)
Here are some thoughts.
Before starting going deep into the code, I would like to understand the use case. There are two scenarios that I can think of where memcached could be used:
no database, just memcached
In this case, memcached is the main repository, no other database is used. The approach you are presenting is good for this scenario. However, I can't think of a real use case for this scenario, where all the data is stored in a volatile memory, with no persistence. Probably there are some, but it is more a exception. In this case would be worth the effort?
database + memcached
Here, the memcached is used as a cache for the database.
In this case, the glue should be a cache adapter (or something like that [1]), not a repository.
The adapter wouldn't need a data mapper to save the entity, the serialization is straightforward (JSON.stringify) and could use the metadata to set the key (entity IDs).
To fetch the entity, the adapter would need a data mapper to deserialize the a valid entity since it would not interact with the repository. And fallback to the repository if the entity is not in the cache.
The adapter should be able to work with any repository. This can be a challenge, since the adapter would need to know the the interface of different repositories (herbs2knex, herbs2mongo, etc).
// very simplified example
const User =
entity('User', {
id: id(String),
nickname: field(String),
password: field(String)
})
const user = new User({ id: '1', nickname: 'john', password: '123' })
const userRepo = new UserRepo()
const userCache = new UserCache(userRepo)
await userCache.insert(user, { ttl: 1000 })
const userFromCache = await userCache.getById('1')
[1] If not a adapter, maybe a chain of responsibility of repositories, where the first handler is the cache and the second is the repository.
Does it make sense?
from herbs.
Related Issues (20)
- New herb, complement a herb or use some market lib to transforms and conversions? HOT 6
- [CI] - Codecov deprecration of v1 HOT 1
- Create a XLSX spreadsheet glue from the output of an USECASE HOT 4
- Hard to identify the reason of an error HOT 5
- Aloe - Capturing domain knowledge using test scenarios HOT 11
- A suggestion to improve code generation HOT 3
- Blog posts suggestions HOT 3
- Add status badge in all repositories HOT 2
- Code owners feature HOT 1
- CLI - What would the future of a new CLI look like?
- Native queue support HOT 1
- New Glue - Herbs2Serverless HOT 1
- Live metrics - audit trail HOT 1
- How can we pass authentication/authorization data more implicitly? HOT 1
- Upgrade node version to 16.x HOT 1
- Herbs DB Migrations - Change your domain and your database will follow
- Enable intellisense in IDE HOT 1
- Implement Performance Measurement APIs from Node.js in AuditTrail for HerbsJS Framework HOT 1
- Typescript support And class-based Use Case
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from herbs.