I was just looking over Bill Katz' counter code ( http://billkatz.com/2008/10/Fault-tolerant-counters-for-App-Engine ) and had a question about a reasonable pattern for using it in the following situation: - I want to count daily usage in certain parts of my site by each user.
Right now I have a UserStats model which has the user, the date, and a reference to a counter. Previously I was using a more simplistic sharded counter that was based on the db.Model, rather than a python object, so in my UserStats model I could write a simple method called get_daily_counter to get counter results for the day with a line like this: def get_daily_counter(self, counter_key): return Counter.get_or_insert(counter_key, name=counter_key) The above would create the counter entity for the day if it didn't exist, and then I could get the count, in my view. With the new code, we have a python object rather than a model I can get_or_insert, so I am wondering if the following seems like a reasonable pattern for GAE: def get_daily_counter(self, counter_key): if not counter_key in vars().keys(): vars()[counter_key] = Counter(counter_name) return vars()[counter_key] If not, is there a recommended way for implementing this counter such that it gets instantiated if not already in existence, and returned appropriately if so? Thanks, -Josh --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Google App Engine" group. To post to this group, send email to google-appengine@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en -~----------~----~----~----~------~----~------~--~---