# Path: cydra/component.py
# class Interface(object):
#     """Marker base class for extension point interfaces.
# 
#     Behavior of the ExtensionPoints for an interface can be customized with
#     _iface_XY class attributes. These behaviors are specified in the interface
#     in order to establish common ground rules in accessing the components for
#     an interface."""
# 
#     _iface_single_extension = False
#     """Only allow one active component for this interface"""
# 
#     _iface_attribute_proxy = None
#     """Callable to use for attribute access
# 
#     The callable will receive the paramenters interface, components and name (in this order)"""
# 
#     _iface_disable_extension_cache = False
#     """Disable the cache for the active extensions"""
# 
# class Component(object):
#     """Base class for components.
# 
#     Every component can declare what extension points it provides, as
#     well as what extension points of other components it extends.
#     """
#     __metaclass__ = ComponentMeta
#     __config = None
# 
#     #: Component Manager of this Component
#     compmgr = None
# 
#     @staticmethod
#     def implements(*interfaces):
#         """Can be used in the class definition of `Component`
#         subclasses to declare the extension points that are extended.
#         """
#         import sys
# 
#         frame = sys._getframe(1)
#         locals_ = frame.f_locals
# 
#         # Some sanity checks
#         assert locals_ is not frame.f_globals and '__module__' in locals_, \
#                'implements() can only be used in a class definition'
# 
#         locals_.setdefault('_implements', []).extend(interfaces)
# 
#     def get_component_name(self):
#         return self.__class__.__module__ + '.' + self.__class__.__name__
# 
#     def get_component_shortname(self):
#         return self.__class__.__name__
# 
#     def get_component_config(self, default=None):
#         if default is None:
#             default = {}
#         return self.compmgr.config.get_component_config(self.get_component_name(), default)
# 
#     @property
#     def component_config(self):
#         if self.__config is None:
#             self.__config = self.get_component_config()
# 
#         return self.__config
# 
# @staticmethod
# def implements(*interfaces):
#     """Can be used in the class definition of `Component`
#     subclasses to declare the extension points that are extended.
#     """
#     import sys
# 
#     frame = sys._getframe(1)
#     locals_ = frame.f_locals
# 
#     # Some sanity checks
#     assert locals_ is not frame.f_globals and '__module__' in locals_, \
#            'implements() can only be used in a class definition'
# 
#     locals_.setdefault('_implements', []).extend(interfaces)
# 
# Path: cydra/util.py
# class SimpleCache(object):
#     """A simple in-memory cache
# 
#     This class does not do any locking. This means that keys should map to
#     relatively stable, immutable values"""
#     def __init__(self, lifetime=30, killtime=None, maxsize=100):
#         self.data = {}
#         self.lifetime = lifetime
#         self.maxsize = maxsize
# 
#         if killtime is None:
#             self.killtime = lifetime * 10
#         else:
#             self.killtime = killtime
# 
#     def set(self, key, value):
#         self.data[key] = SimpleCacheItem(value)
# 
#         if len(self.data) > self.maxsize:
#             self._remove_oldest()
# 
#     def cached(self, key, func):
#         self._remove_old()
#         if key in self.data:
#             return self.data[key].value
#         else:
#             res = func()
#             self.set(key, res)
#             return res
# 
#     def get(self, key, default=None):
#         self._remove_old()
#         item = self.data.get(key)
#         if item is not None:
#             return item.value
#         else:
#             return default
# 
#     def __contains__(self, key):
#         self._remove_old()
#         return key in self.data
# 
#     def _remove_old(self):
#         t = time.time()
# 
#         for key, item in self.data.items():
#             if t - item.creation > self.killtime or t - item.last_access > self.lifetime:
#                 del(self.data[key])
# 
#     def _remove_oldest(self):
#         mintime = time.time()
#         minkey = None
# 
#         for key, item in self.data.items():
#             if item.last_access < mintime:
#                 mintime = item.last_access
#                 minkey = key
# 
#         if minkey is not None:
#             del(self.data[minkey])


from cydra.component import Interface, Component, implements
from cydra.util import SimpleCache
    def add_users(self, users):
        pass

    def get_group(self, groupid):
        pass

    def get_groups(self, groupids):
        pass

    def add_groups(self, groups):
        pass


class MemorySubjectCache(Component):
    """Caches subjects in memory
    """

    implements(ISubjectCache)

    def __init__(self):
        config = self.get_component_config()
        groupttl = config.get('group_ttl', 60 * 60 * 24 * 14)
        groupsize = config.get('group_size', 50)
        userttl = config.get('user_ttl', 5 * 60)
        usersize = config.get('user_size', 500)

        self.groupcache = SimpleCache(
            lifetime=groupttl,
            killtime=groupttl,
            maxsize=groupsize)

# Path: cydra/component.py
# class Interface(object):
#     """Marker base class for extension point interfaces.
# 
#     Behavior of the ExtensionPoints for an interface can be customized with
#     _iface_XY class attributes. These behaviors are specified in the interface
#     in order to establish common ground rules in accessing the components for
#     an interface."""
# 
#     _iface_single_extension = False
#     """Only allow one active component for this interface"""
# 
#     _iface_attribute_proxy = None
#     """Callable to use for attribute access
# 
#     The callable will receive the paramenters interface, components and name (in this order)"""
# 
#     _iface_disable_extension_cache = False
#     """Disable the cache for the active extensions"""
# 
# class Component(object):
#     """Base class for components.
# 
#     Every component can declare what extension points it provides, as
#     well as what extension points of other components it extends.
#     """
#     __metaclass__ = ComponentMeta
#     __config = None
# 
#     #: Component Manager of this Component
#     compmgr = None
# 
#     @staticmethod
#     def implements(*interfaces):
#         """Can be used in the class definition of `Component`
#         subclasses to declare the extension points that are extended.
#         """
#         import sys
# 
#         frame = sys._getframe(1)
#         locals_ = frame.f_locals
# 
#         # Some sanity checks
#         assert locals_ is not frame.f_globals and '__module__' in locals_, \
#                'implements() can only be used in a class definition'
# 
#         locals_.setdefault('_implements', []).extend(interfaces)
# 
#     def get_component_name(self):
#         return self.__class__.__module__ + '.' + self.__class__.__name__
# 
#     def get_component_shortname(self):
#         return self.__class__.__name__
# 
#     def get_component_config(self, default=None):
#         if default is None:
#             default = {}
#         return self.compmgr.config.get_component_config(self.get_component_name(), default)
# 
#     @property
#     def component_config(self):
#         if self.__config is None:
#             self.__config = self.get_component_config()
# 
#         return self.__config
# 
# @staticmethod
# def implements(*interfaces):
#     """Can be used in the class definition of `Component`
#     subclasses to declare the extension points that are extended.
#     """
#     import sys
# 
#     frame = sys._getframe(1)
#     locals_ = frame.f_locals
# 
#     # Some sanity checks
#     assert locals_ is not frame.f_globals and '__module__' in locals_, \
#            'implements() can only be used in a class definition'
# 
#     locals_.setdefault('_implements', []).extend(interfaces)
# 
# Path: cydra/util.py
# class SimpleCache(object):
#     """A simple in-memory cache
# 
#     This class does not do any locking. This means that keys should map to
#     relatively stable, immutable values"""
#     def __init__(self, lifetime=30, killtime=None, maxsize=100):
#         self.data = {}
#         self.lifetime = lifetime
#         self.maxsize = maxsize
# 
#         if killtime is None:
#             self.killtime = lifetime * 10
#         else:
#             self.killtime = killtime
# 
#     def set(self, key, value):
#         self.data[key] = SimpleCacheItem(value)
# 
#         if len(self.data) > self.maxsize:
#             self._remove_oldest()
# 
#     def cached(self, key, func):
#         self._remove_old()
#         if key in self.data:
#             return self.data[key].value
#         else:
#             res = func()
#             self.set(key, res)
#             return res
# 
#     def get(self, key, default=None):
#         self._remove_old()
#         item = self.data.get(key)
#         if item is not None:
#             return item.value
#         else:
#             return default
# 
#     def __contains__(self, key):
#         self._remove_old()
#         return key in self.data
# 
#     def _remove_old(self):
#         t = time.time()
# 
#         for key, item in self.data.items():
#             if t - item.creation > self.killtime or t - item.last_access > self.lifetime:
#                 del(self.data[key])
# 
#     def _remove_oldest(self):
#         mintime = time.time()
#         minkey = None
# 
#         for key, item in self.data.items():
#             if item.last_access < mintime:
#                 mintime = item.last_access
#                 minkey = key
# 
#         if minkey is not None:
#             del(self.data[minkey])


# Path: cydra/caching/subject.py
from cydra.component import Interface, Component, implements
from cydra.util import SimpleCache

    def add_users(self, users):
        pass

    def get_group(self, groupid):
        pass

    def get_groups(self, groupids):
        pass

    def add_groups(self, groups):
        pass


class MemorySubjectCache(Component):
    """Caches subjects in memory
    """

    implements(ISubjectCache)

    def __init__(self):
        config = self.get_component_config()
        groupttl = config.get('group_ttl', 60 * 60 * 24 * 14)
        groupsize = config.get('group_size', 50)
        userttl = config.get('user_ttl', 5 * 60)
        usersize = config.get('user_size', 500)

        self.groupcache = SimpleCache(
            lifetime=groupttl,
            killtime=groupttl,
            maxsize=groupsize)

        self.usercache = SimpleCache(