https://github.com/h2337/cppdataloader
cppdataloader is a batching and caching library for C++17
https://github.com/h2337/cppdataloader
batch batching cache caching cpp cpp17 dataloader
Last synced: 8 months ago
JSON representation
cppdataloader is a batching and caching library for C++17
- Host: GitHub
- URL: https://github.com/h2337/cppdataloader
- Owner: h2337
- License: mit
- Created: 2022-08-31T22:51:14.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2025-07-19T17:04:13.000Z (9 months ago)
- Last Synced: 2025-08-04T08:58:44.150Z (8 months ago)
- Topics: batch, batching, cache, caching, cpp, cpp17, dataloader
- Language: C++
- Homepage:
- Size: 3.91 KB
- Stars: 5
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# cppdataloader
cppdataloader is a batching and caching library for C++17.
cppdataloader is a generic utility to be used as part of your application's data fetching layer to provide a simplified and consistent API over various remote data sources such as databases or web services via batching and caching.
## Features
- [x] Batching
- [x] Caching
- [x] Direct dispatch
- [ ] Timeout dispatch
- [ ] Empty values
## Quickstart
cppq is a header-only library with no dependencies.
Just include the header: `#include "cppdataloader.h"`.
## Example
```c++
#include "cppdataloader.hpp"
#include
class User {
public:
User(long _id): id(_id) {}
long id;
};
class UserBatchLoader : public BatchLoader {
public:
std::vector load(std::vector userIds) const override {
auto result = std::vector();
// Make a DB call here or something and pass in userIds to SELECT and return
for (auto userId : userIds)
result.push_back(User(userId));
// Results should be in the same order as passed-in IDs
return result;
}
};
int main(int argc, char *argv[]) {
UserBatchLoader userBatchLoader = UserBatchLoader();
DataLoader userLoader = DataLoader(userBatchLoader);
std::future load1 = userLoader.load(1);
std::future load2 = userLoader.load(2);
// Since this fetches the same ID of `1`, it will return the cached value
std::future load3 = userLoader.load(1);
// Both calls to `load` will be batched and executed with this call
userLoader.dispatch();
std::cout << load1.get().id << " " << load2.get().id << " " << load3.get().id << std::endl;
}
```
## License
cppdataloader is MIT-licensed.