[Zope3-checkins] CVS: Zope3/src/zope/app/interfaces/cache - __init__.py:1.1.2.1 cache.py:1.1.2.1 ram.py:1.1.2.1
Jim Fulton
jim@zope.com
Mon, 23 Dec 2002 14:31:48 -0500
Update of /cvs-repository/Zope3/src/zope/app/interfaces/cache
In directory cvs.zope.org:/tmp/cvs-serv19908/zope/app/interfaces/cache
Added Files:
Tag: NameGeddon-branch
__init__.py cache.py ram.py
Log Message:
Initial renaming before debugging
=== Added File Zope3/src/zope/app/interfaces/cache/__init__.py ===
#
# This file is necessary to make this directory a package.
=== Added File Zope3/src/zope/app/interfaces/cache/cache.py ===
##############################################################################
#
# Copyright (c) 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (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.
#
##############################################################################
"""
$Id: cache.py,v 1.1.2.1 2002/12/23 19:31:45 jim Exp $
"""
from zope.interface import Interface
from zope.component import getService
from zope.component.exceptions import ComponentLookupError
from zope.proxy.context import ContextProperty
import zope.schema
class CacheName(Zope.Schema.TextLine):
"""Cache Name"""
def __allowed(self):
"""Note that this method works only if the Field is context wrapped."""
try:
caching_service = getService(self.context, "Caching")
except ComponentLookupError:
return ['']
else:
return [''] + list(caching_service.getAvailableCaches())
allowed_values = ContextProperty(__allowed)
class ICacheable(Interface):
"""Object that can be associated with a cache manager."""
cacheId = CacheName(
title=u"Cache Name",
description=u"The name of the cache used for this object.",
required=True)
def getCacheId():
"""Gets the associated cache manager ID."""
def setCacheId(id):
"""Sets the associated cache manager ID."""
"""
$Id: cache.py,v 1.1.2.1 2002/12/23 19:31:45 jim Exp $
"""
from zope.interface import Interface
class ICachingService(Interface):
def getCache(name):
"""Returns a cache object by name."""
def queryCache(name, default):
"""Return a cache object by name or default."""
def getAvailableCaches():
"""Returns a list of names of cache objects known to this caching service."""
"""
$Id: cache.py,v 1.1.2.1 2002/12/23 19:31:45 jim Exp $
"""
from zope.interface import Interface
class ICache(Interface):
"""Interface for caches."""
def invalidate(ob, key=None):
"""Invalidates cached entries that apply to the given object.
ob is an object location. If key is specified, only
invalidates entry for the given key. Otherwise invalidates
all entries for the object.
"""
def invalidateAll():
"""Invalidates all cached entries."""
def query(ob, key=None, default=None):
"""Returns the cached data previously stored by set().
ob is the location of the content object being cached. key is
a mapping of keywords and values which should all be used to
select a cache entry.
"""
def set(data, ob, key=None):
"""Stores the result of executing an operation."""
=== Added File Zope3/src/zope/app/interfaces/cache/ram.py ===
##############################################################################
#
# Copyright (c) 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (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.
#
##############################################################################
"""
$Id: ram.py,v 1.1.2.1 2002/12/23 19:31:45 jim Exp $
"""
from zope.app.interfaces.cache.cache import ICache
from zope.interfaces.event import ISubscriber
from zope.interface.element import Attribute
class IRAMCache(ICache, ISubscriber):
"""Interface for the RAM Cache."""
maxEntries = Attribute("""A maximum number of cached values.""")
maxAge = Attribute("""Maximum age for cached values in seconds.""")
cleanupInterval = Attribute("""An interval between cache cleanups
in seconds.""")
def getStatistics():
"""Reports on the contents of a cache.
The returned value is a sequence of dictionaries with the
following keys:
'path', 'hits', 'misses', 'size', 'entries'
"""
def update(maxEntries, maxAge, cleanupInterval):
"""Saves the parameters available to the user"""