Package lldb :: Package formatters :: Module cache |
[hide private]
[frames] | no frames]

# Source Code for Module lldb.formatters.cache

     1  """
     2  Objective-C runtime wrapper for use by LLDB Python formatters
     3
     4  part of The LLVM Compiler Infrastructure
     5  This file is distributed under the University of Illinois Open Source
     6  License. See LICENSE.TXT for details.
     7  """
     8  import lldb.formatters.metrics
     9
    10
    11 -class Cache:
    12
    13 -    def __init__(self):
    14          self.data = {}
    15          self.statistics = lldb.formatters.metrics.Metrics()
    16          self.statistics.add_metric('hit')
    17          self.statistics.add_metric('miss')
    18
    19 -    def look_for_key(self, key):
    20          if key in self.data:
    21              return True
    22          return False
    23
    24 -    def add_item(self, key, value, ok_to_replace=True):
    25          if not(ok_to_replace) and self.look_for_key(key):
    26              return False
    27          self.data[key] = value
    28          return True
    29
    30 -    def get_value(self, key, default=None):
    31          if self.look_for_key(key):
    32              self.statistics.metric_hit('hit', key)
    33              return self.data[key]
    34          else:
    35              self.statistics.metric_hit('miss', key)
    36              return default
    37