collections-cache 0.3.0.20250303__py3-none-any.whl → 0.3.2.20250303__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,4 @@
1
+ import atexit
1
2
  import pickle
2
3
  import sqlite3
3
4
  from random import choice
@@ -7,20 +8,24 @@ from concurrent.futures import ProcessPoolExecutor as Pool
7
8
  from concurrent.futures import ThreadPoolExecutor as Thread
8
9
 
9
10
  class Collection_Cache:
10
- def __init__(self, collection_name: str, size_limit:int = 800):
11
+ def __init__(self, collection_name: str, constant_per_core: int = 100):
11
12
  # Variables
12
13
  self.collection_name = collection_name
14
+ self.constant_per_core = constant_per_core
13
15
  self.cpu_cores = cpu_count()
16
+ self.size_limit = self.constant_per_core * self.cpu_cores
14
17
  self.collection_dir = path.join("./Collections", self.collection_name)
15
18
  self.databases_list = []
16
19
  self.keys_databases = {}
17
20
  self.temp_keys_values = {}
18
- self.size_limit = size_limit
19
21
 
20
22
  # Init methods
21
23
  self.create_collection()
22
24
  self.get_all_databases()
23
25
 
26
+ # Shutdown method
27
+ atexit.register(self.shutdown)
28
+
24
29
  def configure_connection(self, conn):
25
30
  conn.executescript("""
26
31
  PRAGMA auto_vacuum = FULL;
@@ -75,6 +80,9 @@ class Collection_Cache:
75
80
  elif type_of_operation == "get_key":
76
81
  self.set_multi_keys(self.temp_keys_values)
77
82
  self.temp_keys_values = {}
83
+ elif type_of_operation == "set_key_force":
84
+ self.set_multi_keys(self.temp_keys_values)
85
+ self.temp_keys_values = {}
78
86
 
79
87
  # Experimental
80
88
  def set_key(self, key: str, value: any):
@@ -158,3 +166,7 @@ class Collection_Cache:
158
166
  def export_to_json(self):
159
167
  """Test"""
160
168
  pass
169
+
170
+ def shutdown(self):
171
+ """Save all keys to the collection before close or shutdown"""
172
+ self.verify_size_of_temp_queue("set_key_force")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: collections-cache
3
- Version: 0.3.0.20250303
3
+ Version: 0.3.2.20250303
4
4
  Summary: collections-cache is a Python package for managing data collections across multiple SQLite databases. It allows efficient storage, retrieval, and updating of key-value pairs, supporting various data types serialized with pickle. The package uses parallel processing for fast access and manipulation of large collections.
5
5
  License: MIT
6
6
  Author: Luiz-Trindade
@@ -0,0 +1,6 @@
1
+ collections_cache/__init__.py,sha256=uUp8lhp-HnZRumnU_8MT6qVq95t0pOzn7oLW7ARbnvc,48
2
+ collections_cache/collections_cache.py,sha256=L8w7TL5yIDKzB7o-5Xs_CLlEGFJ3vWoYtV7vpFkHboE,6390
3
+ collections_cache-0.3.2.20250303.dist-info/LICENSE,sha256=RAIL-FmXSiNRgyiVlfhm2SvVI4XDVsN0jDt9207SJ8o,1168
4
+ collections_cache-0.3.2.20250303.dist-info/METADATA,sha256=Cq21wcpwkXxQ601tIF8hikagnYoRZZu_6xNX5sdfTG0,4993
5
+ collections_cache-0.3.2.20250303.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
6
+ collections_cache-0.3.2.20250303.dist-info/RECORD,,
@@ -1,6 +0,0 @@
1
- collections_cache/__init__.py,sha256=uUp8lhp-HnZRumnU_8MT6qVq95t0pOzn7oLW7ARbnvc,48
2
- collections_cache/collections_cache.py,sha256=axISYjklpAWbGVusD2HRq_b9bKpB5i0FAd3xeFe_nIs,5920
3
- collections_cache-0.3.0.20250303.dist-info/LICENSE,sha256=RAIL-FmXSiNRgyiVlfhm2SvVI4XDVsN0jDt9207SJ8o,1168
4
- collections_cache-0.3.0.20250303.dist-info/METADATA,sha256=YQIUhoGw1QFEMQkHc1Ql16V-h5dXDQJrBnOkwGcoOqk,4993
5
- collections_cache-0.3.0.20250303.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
6
- collections_cache-0.3.0.20250303.dist-info/RECORD,,