Comments (7)
can you provide your implementation details?
like, how do you create controllers using 'super'?
if you can tell me more about your case, I will add your case in the test
thanks
from nestjs-omacache.
So, I have a generic exchange controller
export class GenericExchangeController implements IGenericExchangeController {
protected logger = new Logger(this.constructor.name);
constructor(
protected readonly exchangeService: ExchangeService,
protected readonly bankSyncService: BankSyncService,
protected readonly provider?: SourceProvider
) {
if (!provider) this.provider = null;
}
@Get('getTicker24h')
@CacheTTL(5 * MINUTES)
@UseInterceptors(CacheInterceptor)
async getTicker24h(@Query() params: ZTickersParamsDto): Promise<ITickerResponse[]> {
return this.exchangeService.execPublic(this.provider, 'fetchTickers', params);
}
...
}
and then multiple controllers for each provider using the generic controller
@Controller(`provider/binance`)
export class BinanceController extends GenericExchangeController implements IBinanceController {
constructor(
protected readonly exchangeService: ExchangeService,
protected readonly bankSyncService: BankSyncService
) {
super(exchangeService, bankSyncService, 'binance');
}
....
}
@Controller(`provider/coinbase`)
export class CoinbaseController extends GenericExchangeController implements ICoinbaseController {
constructor(
protected readonly exchangeService: ExchangeService,
protected readonly bankSyncService: BankSyncService
) {
super(exchangeService, bankSyncService, 'coinbase');
}
}
Then, endpoints calls are like
GET /provider/binance/getTicker24h
GET /provider/coinbase/getTicker24h
and so on.
from nestjs-omacache.
ah, now I get it clearly.
I have few ideas, but I'm trying not to be too hacky, which is dangerous for future nest's changes.
I'll share when I find out some good ways.
and of course, I'm always open, so tell me your ideas anytime
thank you for using this package
from nestjs-omacache.
I think a good way to handle it would be to use something like that
And construct the cache key name from a variable. That way, we can control it in controller as well as service and the user can chose how he wants to construct his cache key name (or prefix maybe ?) directly in the class constructor.
from nestjs-omacache.
thanks! I'll check it out
from nestjs-omacache.
how about using custom param decorator and use index of it?
for example,
export const FullUrl = createParamDecorator(
(data: unknown, ctx: ExecutionContext) => {
const request = ctx.switchToHttp().getRequest();
const fullUrl = ...
return fullUrl
},
);
and use it in parent class like
export class GenericExchangeController implements IGenericExchangeController {
protected logger = new Logger(this.constructor.name);
constructor(
protected readonly exchangeService: ExchangeService,
protected readonly bankSyncService: BankSyncService,
protected readonly provider?: SourceProvider
) {
if (!provider) this.provider = null;
}
@Get('getTicker24h')
@CacheStorage({
key: `getTicker24h`,
kind: 'temporal',
ttl: 60,
paramIndex: [0,1],
})
async getTicker24h(@Query() params: ZTickersParamsDto, @FullUrl() fullUrl: string): Promise<ITickerResponse[]> {
return this.exchangeService.execPublic(this.provider, 'fetchTickers', params);
}
...
}
I think this would do the job
from nestjs-omacache.
Should I close this issue?
Let me know if you need anything
from nestjs-omacache.
Related Issues (9)
- Bust all cache with params HOT 5
- How do i manage the transaction process in omacache HOT 2
- bust multiple cache keys HOT 1
- BustAllChildren does not exist in type CacheOptions HOT 2
- Handle null parameters value HOT 3
- Nest can't resolve dependencies of the CacheService (DiscoveryService, MetadataScanner, ?) HOT 5
- Update reflect-metadata version on peer deps. HOT 3
- persistent kind Internal Server Error HOT 1
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 nestjs-omacache.