~therve/storm/twisted-integration

« back to all changes in this revision

Viewing changes to storm/store.py

Merged variable_cache_size [r=jamesh,jkakar] [a=lightyear] [f=257267]

Store's constructor takes an optional cache_size keyword argument
representing the maximum number of objects to keep alive in the
cache at any time.  The default is 100, the same as it was before.

Show diffs side-by-side

added added

removed removed

Lines of Context:
49
49
PENDING_REMOVE = 2
50
50
 
51
51
 
 
52
# The maximum number of objects the cache should have per default.
 
53
DEFAULT_CACHE_SIZE = 100
 
54
 
 
55
 
52
56
class Store(object):
53
57
    """The Storm Store.
54
58
 
63
67
 
64
68
    _result_set_factory = None
65
69
 
66
 
    def __init__(self, database):
 
70
    def __init__(self, database, cache_size=DEFAULT_CACHE_SIZE):
67
71
        """
68
72
        @param database: The L{storm.database.Database} instance to use.
 
73
        @param cache_size: The maximum number of objects the internal cache
 
74
            should keep alive.  Defaults to L{DEFAULT_CACHE_SIZE}.
69
75
        """
70
76
        self._connection = database.connect()
71
77
        self._alive = WeakValueDictionary()
72
78
        self._dirty = {}
73
79
        self._order = {} # (info, info) = count
74
 
        self._cache = Cache(100)
 
80
        self._cache = Cache(cache_size)
75
81
        self._implicit_flush_block_count = 0
76
82
        self._sequence = 0 # Advisory ordering.
77
83
        self._event = EventSystem(self)