/usr/share/pyshared/provisioningserver/cache.py is in python-maas-provisioningserver 1.2+bzr1373+dfsg-0ubuntu1~12.04.6.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | # Copyright 2012 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
"""API credentials for node-group workers."""
from __future__ import (
absolute_import,
print_function,
unicode_literals,
)
__metaclass__ = type
__all__ = [
'cache',
'initialize',
]
from multiprocessing import Manager
class Cache(object):
"""A process-safe dict-like cache."""
def __init__(self, cache_backend):
self.cache_backend = cache_backend
def set(self, key, value):
self.cache_backend[key] = value
def get(self, key):
return self.cache_backend.get(key, None)
def clear(self):
self.cache_backend.clear()
_manager = None
cache = None
initialized = False
def initialize():
"""Initialize cache of shared data between processes.
This needs to be done exactly once, by the parent process, before it
start forking off workers.
"""
global _manager
global cache
global initialized
if not initialized:
_manager = Manager()
cache = Cache(_manager.dict())
initialized = True
|