Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Dennis Lee Bieber Newsgroups: comp.lang.python Subject: Re: Cannot get the value from dogpile.cache from different modules. Date: Tue, 29 Dec 2015 17:49:07 -0500 Organization: IISS Elusive Unicorn Lines: 68 Message-ID: References: <7c8df879-b03a-4323-90c5-3221dd1eced2@googlegroups.com> <337dc80d-bd55-4976-a716-fc8f793a1322@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de 12kYgpQ+vI8fAIg/m9eNwAVJ8ak5tRakKSxWwcqe/GsQ== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'static': 0.03; '"""': 0.05; 'cache': 0.05; 'exist,': 0.07; 'message-id:@4ax.com': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'type)': 0.09; 'python': 0.10; 'def': 0.13; '(string)': 0.16; 'attributes.': 0.16; 'cache:': 0.16; 'list)': 0.16; 'mailinglist': 0.16; 'received:80.91.229.3': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'url:home': 0.18; 'creates': 0.18; '2015': 0.20; 'java': 0.22; 'dec': 0.23; 'import': 0.24; 'module': 0.25; 'header:X-Complaints- To:1': 0.26; 'defining': 0.27; 'subject:skip:d 10': 0.27; 'value)': 0.29; 'code': 0.30; 'skip:s 30': 0.31; 'returned': 0.32; 'class': 0.33; 'shift': 0.33; 'definition': 0.34; 'tue,': 0.34; 'list': 0.34; 'saved': 0.35; 'data.': 0.36; 'skip:m 40': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'method': 0.37; 'received:org': 0.37; 'charset:us-ascii': 0.37; 'delete': 0.38; 'data': 0.39; 'does': 0.39; 'subject:from': 0.39; 'subject:the': 0.39; 'to:addr:python.org': 0.40; 'save': 0.60; '>from': 0.76; 'subject:get': 0.81; 'subject:value': 0.84; 'dennis': 0.91 X-Injected-Via-Gmane: http://gmane.org/ X-Gmane-NNTP-Posting-Host: adsl-108-79-218-6.dsl.klmzmi.sbcglobal.net X-Newsreader: Forte Agent 6.00/32.1186 X-No-Archive: YES X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:100973 On Tue, 29 Dec 2015 09:27:02 -0800 (PST), xeon Mailinglist declaimed the following: > >Here is the full class that I use to store the data. > >from dogpile.cache import make_region > > ># my_dictionary = {} >region = make_region().configure('dogpile.cache.memory') ># arguments={"cache_dict":my_dictionary}) >class Cache: > > @staticmethod > def save(key, value): > """ > general purpose method to save data (value) in the cache > > :param key (string) key of the value to be saved in cache > :param value (any type) the value to be saved > """ > region.set(key, value) > > @staticmethod > def get(key): > """ > general purpose method to get data from the cache > > :param key (string) key of the data to be fetched > :return value (any type) data to be returned from the cache > """ > return region.get(key) > > > @staticmethod > def get_or_create(key): > """ > General purpose method to get data from the cache. If the value does not exist, it creates a list > > :param: key (string) key of the data to be fetched > :return value (any type) data to be returned from the cache > """ > return region.get_or_create(key, list) > > @staticmethod > def set_job_predictions(rank_list): > Cache.save("job_predictions", rank_list) > > @staticmethod > def get_job_predictions(): > return Cache.get("job_predictions") You are defining a Python class in which EVERY method is a static method... Smells like Java code to me... Delete the class definition line, shift all the methods left and reference them as module attributes. import theModule keyx = theModule.get_key("a key") -- Wulfraed Dennis Lee Bieber AF6VN wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/