1
# -*- coding: utf-8 -*-
3
# Authors: Natalia B Bidart <natalia.bidart@canonical.com>
5
# Copyright 2011 Canonical Ltd.
7
# This program is free software: you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License version 3, as published
9
# by the Free Software Foundation.
11
# This program is distributed in the hope that it will be useful, but
12
# WITHOUT ANY WARRANTY; without even the implied warranties of
13
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
14
# PURPOSE. See the GNU General Public License for more details.
16
# You should have received a copy of the GNU General Public License along
17
# with this program. If not, see <http://www.gnu.org/licenses/>.
19
"""The base object that holds a backend instance."""
21
from ubuntuone.controlpanel import backend
25
"""The base object that caches stuff."""
30
def __init__(self, *args, **kwargs):
31
"""Initialize the object using 'backend' as backend."""
32
super(Cache, self).__init__()
33
if self.logger is not None:
34
self.logger.debug('%s: started.', self.__class__.__name__)
36
def get_backend(self):
37
"""A cached ControlBackend instance."""
38
if not self._shared_objects:
39
self._shared_objects['backend'] = backend.ControlBackend()
40
return self._shared_objects['backend']
42
def set_backend(self, new_value):
43
"""Set a new ControlBackend instance."""
44
self._shared_objects['backend'] = new_value
46
backend = property(fget=get_backend, fset=set_backend)
49
"""Clear all cached objects."""
50
self._shared_objects = {}