### -*- coding: utf-8 -*- ####################################################
##############################################################################
#
# Copyright (c) 2012 Thierry Florac <tflorac AT ulthar.net>
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################


# import standard packages

# import Zope3 interfaces

# import local interfaces
from ztfy.cache.metadirectives import ICacheProxyHandlerBase

# import Zope3 packages
from zope.interface import Interface
from zope.schema import TextLine, Choice

# import local packages

from ztfy.cache import _


class ICacheHandler(Interface):
    """ICacheHandler is a common basic interface to several cache managers"""

    def set(self, namespace, key, value):
        """Set the given value for the given key"""

    def query(self, namespace, key, default=None):
        """Query cache for given key"""

    def invalidate(self, namespace, key):
        """Invalidate key in given namespace"""

    def invalidateAll(self):
        """Invalidate all cache entries"""


class IPersistentCacheProxyHandlerInfo(Interface):
    """Cache proxy handler interface"""

    cache_interface = Choice(title=_("Cache utility interface"),
                             required=True,
                             vocabulary="Interfaces")

    cache_name = TextLine(title=_("Cache utility name"),
                          required=False)


class IPersistentCacheProxyHandler(ICacheProxyHandlerBase, IPersistentCacheProxyHandlerInfo):
    """Persistent cache proxy handler interface"""
