[Zope3-checkins] CVS: Zope3/src/zope/app/interfaces/cache - __init__.py:1.2 cache.py:1.2 ram.py:1.2

Jim Fulton jim@zope.com
Wed, 25 Dec 2002 09:13:59 -0500


Update of /cvs-repository/Zope3/src/zope/app/interfaces/cache
In directory cvs.zope.org:/tmp/cvs-serv15352/src/zope/app/interfaces/cache

Added Files:
	__init__.py cache.py ram.py 
Log Message:
Grand renaming:

- Renamed most files (especially python modules) to lower case.

- Moved views and interfaces into separate hierarchies within each
  project, where each top-level directory under the zope package
  is a separate project.

- Moved everything to src from lib/python.

  lib/python will eventually go away. I need access to the cvs
  repository to make this happen, however.

There are probably some bits that are broken. All tests pass
and zope runs, but I haven't tried everything. There are a number
of cleanups I'll work on tomorrow.



=== Zope3/src/zope/app/interfaces/cache/__init__.py 1.1 => 1.2 ===
--- /dev/null	Wed Dec 25 09:13:58 2002
+++ Zope3/src/zope/app/interfaces/cache/__init__.py	Wed Dec 25 09:12:58 2002
@@ -0,0 +1,2 @@
+#
+# This file is necessary to make this directory a package.


=== Zope3/src/zope/app/interfaces/cache/cache.py 1.1 => 1.2 ===
--- /dev/null	Wed Dec 25 09:13:58 2002
+++ Zope3/src/zope/app/interfaces/cache/cache.py	Wed Dec 25 09:12:58 2002
@@ -0,0 +1,88 @@
+##############################################################################
+#
+# 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.
+#
+##############################################################################
+"""Interfaces for cache manager.
+
+$Id$
+"""
+from zope.interface import Interface
+from zope.component import getService
+from zope.component.exceptions import ComponentLookupError
+from zope.proxy.context import ContextProperty
+from zope.schema import TextLine
+
+class CacheName(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."""
+
+
+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."""
+
+
+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."""


=== Zope3/src/zope/app/interfaces/cache/ram.py 1.1 => 1.2 ===
--- /dev/null	Wed Dec 25 09:13:58 2002
+++ Zope3/src/zope/app/interfaces/cache/ram.py	Wed Dec 25 09:12:58 2002
@@ -0,0 +1,41 @@
+##############################################################################
+#
+# 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$
+"""
+from zope.app.interfaces.cache.cache import ICache
+from zope.interfaces.event import ISubscriber
+from zope.interface 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"""