Skip to content

Commit a5102bf

Browse files
committed
Make RDBMS cache-size configurable.
1 parent da67177 commit a5102bf

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

roundup/backends/rdbms_common.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,6 @@
7171
from sessions_rdbms import Sessions, OneTimeKeys
7272
from roundup.date import Range
7373

74-
# number of rows to keep in memory
75-
ROW_CACHE_SIZE = 100
76-
7774
# dummy value meaning "argument not passed"
7875
_marker = []
7976

@@ -108,7 +105,7 @@ class Database(FileStorage, hyperdb.Database, roundupdb.Database):
108105
109106
- some functionality is specific to the actual SQL database, hence
110107
the sql_* methods that are NotImplemented
111-
- we keep a cache of the latest ROW_CACHE_SIZE row fetches.
108+
- we keep a cache of the latest N row fetches (where N is configurable).
112109
"""
113110
def __init__(self, config, journaltag=None):
114111
""" Open the database and load the schema from it.
@@ -125,6 +122,7 @@ def __init__(self, config, journaltag=None):
125122

126123
# keep a cache of the N most recently retrieved rows of any kind
127124
# (classname, nodeid) = row
125+
self.cache_size = config.RDBMS_CACHE_SIZE
128126
self.cache = {}
129127
self.cache_lru = []
130128
self.stats = {'cache_hits': 0, 'cache_misses': 0, 'get_items': 0,
@@ -1057,7 +1055,7 @@ def getnode(self, classname, nodeid):
10571055
self.cache[key] = node
10581056
# update the LRU
10591057
self.cache_lru.insert(0, key)
1060-
if len(self.cache_lru) > ROW_CACHE_SIZE:
1058+
if len(self.cache_lru) > self.cache_size:
10611059
del self.cache[self.cache_lru.pop()]
10621060

10631061
if __debug__:

roundup/configuration.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ def _value2str(self, value):
370370

371371
class NullableOption(Option):
372372

373-
"""Option that is set to None if it's string value is one of NULL strings
373+
"""Option that is set to None if its string value is one of NULL strings
374374
375375
Default nullable strings list contains empty string only.
376376
There is constructor parameter allowing to specify different nullables.
@@ -592,8 +592,10 @@ def str2value(self, value):
592592
(NullableOption, 'read_default_group', 'roundup',
593593
"Name of the group to use in the MySQL defaults file (.my.cnf).\n"
594594
"Only used in MySQL connections."),
595+
(IntegerNumberOption, 'cache_size', '100',
596+
"Size of the node cache (in elements)"),
595597
), "Settings in this section are used"
596-
" by Postgresql and MySQL backends only"
598+
" by RDBMS backends only"
597599
),
598600
("logging", (
599601
(FilePathOption, "config", "",
@@ -874,7 +876,7 @@ def add_option(self, option):
874876
_options.append(_name)
875877
# (section, name) key is used for writing .ini file
876878
self.options[(_section, _name)] = option
877-
# make the option known under all of it's A.K.A.s
879+
# make the option known under all of its A.K.A.s
878880
for _name in option.aliases:
879881
self.options[_name] = option
880882

0 commit comments

Comments
 (0)