def __init__(self, cache, name, columns=1, keys=1, timeout=0, modified=0, restricted=False): if not self.IsValidName(name): raise exceptions.CacheTableNameInvalid( 'Invalid cache table name [{}] in cache [{}].'.format( name, cache.name)) self._cache = cache self.name = name self.restricted = restricted self.modified = modified self.changed = False self.timeout = timeout or 0 self.columns = columns self.keys = keys # Determine is the table has expired once at initialization time. We expect # callers to keep cache or table objects open for a few seconds at most. # Given that it doesn't make sense to do a few operations in that window # only to have the last one expire. if timeout and modified and (modified + timeout) < Now(): self.Invalidate()
def EncodeName(cls, name): r"""Returns name encoded for file system path compatibility. A table name may be a file name. alnum and '_.-' are not encoded. Args: name: The cache name string to encode. Raises: CacheTableNameInvalid: For invalid table names. Returns: Name encoded for portability. """ if not name: raise exceptions.CacheTableNameInvalid( 'Cache table name [{}] is invalid.'.format(name)) return six.moves.urllib.parse.quote(name, '!@+,')