python Cachetools can items have different ttl?












1















Im using @cachetools.func.ttl_cache(maxsize=3, ttl=3600, timer=time.time, typed=False) to cache different data frames. The function being wrapped doesn't build the DF itself, but given an argument calls the right function.



Depending on the argument the DF may be time consuming or fast to build, given that I want to modify the item ttl (time-to-live). So that item 1 may have ttl=3600 while item 2 ttl=10800.



Is that functionality supported? using a global variable or any other way? docs










share|improve this question



























    1















    Im using @cachetools.func.ttl_cache(maxsize=3, ttl=3600, timer=time.time, typed=False) to cache different data frames. The function being wrapped doesn't build the DF itself, but given an argument calls the right function.



    Depending on the argument the DF may be time consuming or fast to build, given that I want to modify the item ttl (time-to-live). So that item 1 may have ttl=3600 while item 2 ttl=10800.



    Is that functionality supported? using a global variable or any other way? docs










    share|improve this question

























      1












      1








      1








      Im using @cachetools.func.ttl_cache(maxsize=3, ttl=3600, timer=time.time, typed=False) to cache different data frames. The function being wrapped doesn't build the DF itself, but given an argument calls the right function.



      Depending on the argument the DF may be time consuming or fast to build, given that I want to modify the item ttl (time-to-live). So that item 1 may have ttl=3600 while item 2 ttl=10800.



      Is that functionality supported? using a global variable or any other way? docs










      share|improve this question














      Im using @cachetools.func.ttl_cache(maxsize=3, ttl=3600, timer=time.time, typed=False) to cache different data frames. The function being wrapped doesn't build the DF itself, but given an argument calls the right function.



      Depending on the argument the DF may be time consuming or fast to build, given that I want to modify the item ttl (time-to-live). So that item 1 may have ttl=3600 while item 2 ttl=10800.



      Is that functionality supported? using a global variable or any other way? docs







      python pandas caching






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 21 '18 at 4:53









      Carlos P CeballosCarlos P Ceballos

      55111




      55111
























          1 Answer
          1






          active

          oldest

          votes


















          0














          No.



          You can, however, create your own custom caches for use with cachetools. You can check out the implementation of the ttlcache in ttl.py for an example. It's pretty straightforward.



          Unfortunately, the ttlcache itself isn't really designed in such a way that you could conveniently subclass it and override the logic that determines when items in the cache expire. It would be easy enough to just go in and tamper with the expiration dates for the links, but the fact that they used double underscores to prefix all the link-related logic is kind of a clue that the author really didn't want you to do that.



          I'd recommend just implementing your own cache.






          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53405470%2fpython-cachetools-can-items-have-different-ttl%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            No.



            You can, however, create your own custom caches for use with cachetools. You can check out the implementation of the ttlcache in ttl.py for an example. It's pretty straightforward.



            Unfortunately, the ttlcache itself isn't really designed in such a way that you could conveniently subclass it and override the logic that determines when items in the cache expire. It would be easy enough to just go in and tamper with the expiration dates for the links, but the fact that they used double underscores to prefix all the link-related logic is kind of a clue that the author really didn't want you to do that.



            I'd recommend just implementing your own cache.






            share|improve this answer




























              0














              No.



              You can, however, create your own custom caches for use with cachetools. You can check out the implementation of the ttlcache in ttl.py for an example. It's pretty straightforward.



              Unfortunately, the ttlcache itself isn't really designed in such a way that you could conveniently subclass it and override the logic that determines when items in the cache expire. It would be easy enough to just go in and tamper with the expiration dates for the links, but the fact that they used double underscores to prefix all the link-related logic is kind of a clue that the author really didn't want you to do that.



              I'd recommend just implementing your own cache.






              share|improve this answer


























                0












                0








                0







                No.



                You can, however, create your own custom caches for use with cachetools. You can check out the implementation of the ttlcache in ttl.py for an example. It's pretty straightforward.



                Unfortunately, the ttlcache itself isn't really designed in such a way that you could conveniently subclass it and override the logic that determines when items in the cache expire. It would be easy enough to just go in and tamper with the expiration dates for the links, but the fact that they used double underscores to prefix all the link-related logic is kind of a clue that the author really didn't want you to do that.



                I'd recommend just implementing your own cache.






                share|improve this answer













                No.



                You can, however, create your own custom caches for use with cachetools. You can check out the implementation of the ttlcache in ttl.py for an example. It's pretty straightforward.



                Unfortunately, the ttlcache itself isn't really designed in such a way that you could conveniently subclass it and override the logic that determines when items in the cache expire. It would be easy enough to just go in and tamper with the expiration dates for the links, but the fact that they used double underscores to prefix all the link-related logic is kind of a clue that the author really didn't want you to do that.



                I'd recommend just implementing your own cache.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Jan 27 at 8:41









                WillWill

                38048




                38048
































                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53405470%2fpython-cachetools-can-items-have-different-ttl%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    這個網誌中的熱門文章

                    Xamarin.form Move up view when keyboard appear

                    Post-Redirect-Get with Spring WebFlux and Thymeleaf

                    Anylogic : not able to use stopDelay()