Search code examples
pythonzodb

How to set cache size in ZODB?


I establish ZODB connection with the following code:

connection = ZODB.connection('zodb/connect4_reinf.fs')
dbroot = connection.root()

How can I set RAM cache size?


Solution

  • From the source code of class DB:

      def __init__(self, storage,
                 pool_size=7,
                 pool_timeout=1<<31,
                 cache_size=400,
                 cache_size_bytes=0,
                 historical_pool_size=3,
                 historical_cache_size=1000,
                 historical_cache_size_bytes=0,
                 historical_timeout=300,
                 database_name='unnamed',
                 databases=None,
                 xrefs=True,
                 large_record_size=1<<24,
                 **storage_args):
    

    When ZODB.connection is defined as follows:

    def connection(*args, **kw):
        return DB(*args, **kw).open_then_close_db_when_connection_closes()
    

    I would say

       connection = ZODB.connection('zodb/connect4_reinf.fs',
            cache_size=<your-cache-size>)
    

    Also there's a cache_size_bytes if you prefer the limit to be in (estimated) bytes. 0 means unlimited for this parameter.