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

zopefoundation / Zope / 6263629025

21 Sep 2023 03:12PM UTC coverage: 82.146% (-0.01%) from 82.159%
6263629025

Pull #1164

github

web-flow
[pre-commit.ci lite] apply automatic fixes
Pull Request #1164: Move all linters to pre-commit.

4353 of 6963 branches covered (0.0%)

Branch coverage included in aggregate %.

487 of 487 new or added lines in 186 files covered. (100.0%)

27394 of 31684 relevant lines covered (86.46%)

0.86 hits per line

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

23.64
/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.
1✔
14

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

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

22

23
class CacheManager:
1✔
24
    """Cache management mix-in."""
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
        """Returns the name of the classes of the objects in the cache and the
38
        number of objects in the cache for each class."""
39
        detail = self._getDB().cacheDetail()
×
40
        if REQUEST is not None:
×
41
            # format as text
42
            REQUEST.RESPONSE.setHeader('Content-Type', 'text/plain')
×
43
            return '\n'.join(
×
44
                ['%6d %s' % (count, name) for name, count in detail])
45
        # raw
46
        return detail
×
47

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

81

82
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