Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Keith Bamberger 26 posts 106 karma points
    Mar 18, 2020 @ 17:57
    Keith Bamberger
    0

    Architecture tips

    Hi, i have some classes which read from an externa api to gather reviews and scores.

    I have created custom components to show various views from the received data, what i m starting to wonder is, some of my components request the same information (almost) and Im wanting to gather the information from the api just once and when my components are separately rendered they can all read from the same object and not separately contact the externa api every time.

    I guess i could jam it on first read in a session object and then in every component just read from the session object, and then when the page has rendered destroy the session but is there another way? Its possible this object could require more information and need to call the api to read in more data to it along the way, with the session object its just to check of its there and of not add it but as the page is rendered from all the templates and documenttypes along the way there must be a way of reading from this object without stuffing it in a session? Or am i totally wrong

    Any advice?

  • Malthe Petersen 68 posts 383 karma points c-trib
    Mar 18, 2020 @ 19:59
    Malthe Petersen
    0

    Hi Keith.

    Wouldn’t it be possible to do a request cache and save the object that you get from your API call in there?

    I think I would do something like:

    User request webpage -> APIService cache decorator -> APIService.

    So in the decorator you make a dictionary of

    Use Dependency Injection to solve your problem, that is the easiest. And make your service and decorator scoped, because then it will be destroyed when the request finishes.

    Hope this helps a little bit and that I understand your question correctly. Otherwise don’t hesitate asking.

    Regards Malthe

Please Sign in or register to post replies

Write your reply to:

Draft