[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/Caching - Caching.py:1.1

Marius Gedminas mgedmin@codeworks.lt
Thu, 3 Oct 2002 06:37:51 -0400


Update of /cvs-repository/Zope3/lib/python/Zope/App/Caching
In directory cvs.zope.org:/tmp/cvs-serv1357

Added Files:
	Caching.py 
Log Message:
Added getCacheForObject

=== Added File Zope3/lib/python/Zope/App/Caching/Caching.py ===
##############################################################################
#
# Copyright (c) 2001, 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.
# 
##############################################################################
"""Helpers for caching."""

from Zope.ComponentArchitecture import getAdapter, getService
from Zope.App.Caching.ICacheable import ICacheable

def getCacheForObj(obj):
    """Returns the cache associated with obj or None."""
    adapter = getAdapter(obj, ICacheable)
    cache_id = adapter.getCacheId()
    if not cache_id:
        return None
    service = getService(obj, "Caching")
    return service.getCache(cache_id)