• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

zopefoundation / Zope / 11650957671

03 Nov 2024 11:30AM CUT coverage: 82.246%. Remained the same
11650957671

Pull #1234

github

dataflake
Merge branch 'master' into perrinjerome/macosxfails
Pull Request #1234: Fix pre-installation of universal2 environment for OSX tests

3526 of 6003 branches covered (58.74%)

Branch coverage included in aggregate %.

28030 of 32365 relevant lines covered (86.61%)

0.87 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

24.0
/src/App/CacheManager.py
1
##############################################################################
2
#
3
# Copyright (c) 2002 Zope Foundation and Contributors.
4
#
5
# This software is subject to the provisions of the Zope Public License,
6
# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
7
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
8
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
9
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
10
# FOR A PARTICULAR PURPOSE
11
#
12
##############################################################################
13
"""Cache management support.
14

15
This class is mixed into the application manager in App.ApplicationManager.
16
"""
17

18
from AccessControl.class_init import InitializeClass
1✔
19
from Acquisition import aq_parent
1✔
20

21

22
class CacheManager:
1✔
23
    """Cache management mix-in
24
    """
25

26
    def _getDB(self):
1✔
27
        try:
1✔
28
            return self._p_jar.db()
1✔
29
        except AttributeError:
×
30
            return aq_parent(self)._p_jar.db()
×
31

32
    def cache_size(self):
1✔
33
        db = self._getDB()
1✔
34
        return db.getCacheSize()
1✔
35

36
    def cache_detail(self, REQUEST=None):
1✔
37
        """
38
        Returns the name of the classes of the objects in the cache
39
        and the number of objects in the cache for each class.
40
        """
41
        detail = self._getDB().cacheDetail()
×
42
        if REQUEST is not None:
×
43
            # format as text
44
            REQUEST.RESPONSE.setHeader('Content-Type', 'text/plain')
×
45
            return '\n'.join(
×
46
                ['%6d %s' % (count, name) for name, count in detail])
47
        # raw
48
        return detail
×
49

50
    def cache_extreme_detail(self, REQUEST=None):
1✔
51
        """
52
        Returns information about each object in the cache.
53
        """
54
        detail = self._getDB().cacheExtremeDetail()
×
55
        if REQUEST is not None:
×
56
            # sort the list.
57
            lst = [((dict['conn_no'], dict['oid']), dict) for dict in detail]
×
58
            # format as text.
59
            res = [
×
60
                '# Table shows connection number, oid, refcount, state, '
61
                'and class.',
62
                '# States: L = loaded, G = ghost, C = changed']
63
            for sortkey, dict in lst:
×
64
                id = dict.get('id', None)
×
65
                if id:
×
66
                    idinfo = ' (%s)' % id
×
67
                else:
68
                    idinfo = ''
×
69
                s = dict['state']
×
70
                if s == 0:
×
71
                    state = 'L'  # loaded
×
72
                elif s == 1:
×
73
                    state = 'C'  # changed
×
74
                else:
75
                    state = 'G'  # ghost
×
76
                res.append('%d %-34s %6d %s %s%s' % (
×
77
                    dict['conn_no'], repr(dict['oid']), dict['rc'],
78
                    state, dict['klass'], idinfo))
79
            REQUEST.RESPONSE.setHeader('Content-Type', 'text/plain')
×
80
            return '\n'.join(res)
×
81
        else:
82
            # raw
83
            return detail
×
84

85

86
InitializeClass(CacheManager)
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc