collections-cache 0.1.3__py3-none-any.whl → 0.1.5__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.
- collections_cache/collections_cache.py +44 -5
- {collections_cache-0.1.3.dist-info → collections_cache-0.1.5.dist-info}/METADATA +1 -1
- collections_cache-0.1.5.dist-info/RECORD +6 -0
- collections_cache-0.1.3.dist-info/RECORD +0 -6
- {collections_cache-0.1.3.dist-info → collections_cache-0.1.5.dist-info}/LICENSE +0 -0
- {collections_cache-0.1.3.dist-info → collections_cache-0.1.5.dist-info}/WHEEL +0 -0
@@ -3,6 +3,7 @@ from multiprocessing import Pool
|
|
3
3
|
from os import cpu_count, path, makedirs, scandir
|
4
4
|
from itertools import chain
|
5
5
|
from random import choice
|
6
|
+
#from threading import Thread as task
|
6
7
|
import pickle
|
7
8
|
|
8
9
|
class Collection_Cache:
|
@@ -27,7 +28,8 @@ class Collection_Cache:
|
|
27
28
|
|
28
29
|
def initialize_databases(self, db_path):
|
29
30
|
conn = sqlite3.connect(db_path)
|
30
|
-
|
31
|
+
self.configure_connection(conn)
|
32
|
+
#conn.execute("PRAGMA journal_mode=WAL;")
|
31
33
|
conn.execute("""
|
32
34
|
CREATE TABLE IF NOT EXISTS data(
|
33
35
|
key TEXT,
|
@@ -47,8 +49,9 @@ class Collection_Cache:
|
|
47
49
|
|
48
50
|
def get_all_keys(self, database):
|
49
51
|
conn = sqlite3.connect(database)
|
52
|
+
self.configure_connection(conn)
|
50
53
|
cursor = conn.cursor()
|
51
|
-
cursor.execute("PRAGMA journal_mode=WAL;")
|
54
|
+
#cursor.execute("PRAGMA journal_mode=WAL;")
|
52
55
|
cursor.execute("SELECT key FROM data;")
|
53
56
|
result = cursor.fetchall()
|
54
57
|
keys = [(line[0], database) for line in result]
|
@@ -56,12 +59,14 @@ class Collection_Cache:
|
|
56
59
|
return keys
|
57
60
|
|
58
61
|
def set_key(self, key, value):
|
62
|
+
"""Used to store values and associate a value with a key."""
|
59
63
|
if key not in self.keys_databases:
|
60
64
|
database_to_insert = choice(self.databases_list)
|
61
65
|
#print(f"Inserting in {database_to_insert}")
|
62
66
|
conn = sqlite3.connect(database_to_insert)
|
67
|
+
self.configure_connection(conn)
|
63
68
|
cursor = conn.cursor()
|
64
|
-
cursor.execute("PRAGMA journal_mode=WAL;")
|
69
|
+
#cursor.execute("PRAGMA journal_mode=WAL;")
|
65
70
|
cursor.execute("INSERT INTO data(key, value) VALUES (?, ?);", (key, pickle.dumps(value)))
|
66
71
|
conn.commit()
|
67
72
|
conn.close()
|
@@ -71,8 +76,9 @@ class Collection_Cache:
|
|
71
76
|
#print(f"Updating key '{key}' in {self.keys_databases[key]}...")
|
72
77
|
database_to_update = self.keys_databases[key]
|
73
78
|
conn = sqlite3.connect(database_to_update)
|
79
|
+
self.configure_connection(conn)
|
74
80
|
cursor = conn.cursor()
|
75
|
-
cursor.execute("PRAGMA journal_mode=WAL;")
|
81
|
+
#cursor.execute("PRAGMA journal_mode=WAL;")
|
76
82
|
cursor.execute("UPDATE data SET value = ? WHERE key = ?;", (pickle.dumps(value), key))
|
77
83
|
conn.commit()
|
78
84
|
conn.close()
|
@@ -82,14 +88,21 @@ class Collection_Cache:
|
|
82
88
|
self.keys_databases[key] = database
|
83
89
|
#print(self.keys_databases)
|
84
90
|
|
91
|
+
def delete_to_keys_database(self, key):
|
92
|
+
"""Removes the key from the dictionary of stored keys"""
|
93
|
+
if key in self.keys_databases:
|
94
|
+
del self.keys_databases[key]
|
95
|
+
|
85
96
|
def get_key(self, key):
|
97
|
+
"""Used to obtain the value stored by the key"""
|
86
98
|
try:
|
87
99
|
database_to_search = self.keys_databases[key]
|
88
100
|
#print(database_to_search)
|
89
101
|
|
90
102
|
conn = sqlite3.connect(database_to_search)
|
103
|
+
self.configure_connection(conn)
|
91
104
|
cursor = conn.cursor()
|
92
|
-
cursor.execute("PRAGMA journal_mode=WAL;")
|
105
|
+
#cursor.execute("PRAGMA journal_mode=WAL;")
|
93
106
|
cursor.execute("SELECT value FROM data WHERE key = ?", (key,))
|
94
107
|
result = cursor.fetchall()
|
95
108
|
conn.close()
|
@@ -97,3 +110,29 @@ class Collection_Cache:
|
|
97
110
|
|
98
111
|
except Exception as error:
|
99
112
|
return error
|
113
|
+
|
114
|
+
def delete_key(self, key):
|
115
|
+
"""Used to delete the value stored by the key"""
|
116
|
+
try:
|
117
|
+
database_to_delete = self.keys_databases[key]
|
118
|
+
#print(database_to_search)
|
119
|
+
|
120
|
+
conn = sqlite3.connect(database_to_delete)
|
121
|
+
self.configure_connection(conn)
|
122
|
+
cursor = conn.cursor()
|
123
|
+
#cursor.execute("PRAGMA journal_mode=WAL;")
|
124
|
+
cursor.execute("DELETE FROM data WHERE key = ?", (key,))
|
125
|
+
conn.commit()
|
126
|
+
conn.close()
|
127
|
+
self.delete_to_keys_database(key)
|
128
|
+
|
129
|
+
except KeyError:
|
130
|
+
return f"Key '{key}' not found."
|
131
|
+
|
132
|
+
except Exception as error:
|
133
|
+
return error
|
134
|
+
|
135
|
+
def configure_connection(self, conn):
|
136
|
+
conn.execute("PRAGMA journal_mode = WAL;")
|
137
|
+
conn.execute("PRAGMA synchronous = NORMAL;")
|
138
|
+
conn.execute("PRAGMA wal_autocheckpoint = 1000;")
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: collections-cache
|
3
|
-
Version: 0.1.
|
3
|
+
Version: 0.1.5
|
4
4
|
Summary: Collection 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=y85cIYXZW9j_CxKqnrV2OnwbBK6s9fwaBY5-woe32Ro,5288
|
3
|
+
collections_cache-0.1.5.dist-info/LICENSE,sha256=RAIL-FmXSiNRgyiVlfhm2SvVI4XDVsN0jDt9207SJ8o,1168
|
4
|
+
collections_cache-0.1.5.dist-info/METADATA,sha256=dtrLBINwp9heD8SomfCfx2hxoXhyUu0jfFg10kqZiYw,3199
|
5
|
+
collections_cache-0.1.5.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
6
|
+
collections_cache-0.1.5.dist-info/RECORD,,
|
@@ -1,6 +0,0 @@
|
|
1
|
-
collections_cache/__init__.py,sha256=uUp8lhp-HnZRumnU_8MT6qVq95t0pOzn7oLW7ARbnvc,48
|
2
|
-
collections_cache/collections_cache.py,sha256=Lqm9D-UAjPYHKc28yJtdpKpWORxrTGmg7t_1QCC8Pq4,3812
|
3
|
-
collections_cache-0.1.3.dist-info/LICENSE,sha256=RAIL-FmXSiNRgyiVlfhm2SvVI4XDVsN0jDt9207SJ8o,1168
|
4
|
-
collections_cache-0.1.3.dist-info/METADATA,sha256=96NFbdna6GVAYPOTbOi5kk13SOEaUwsHLUKEWMg-iAs,3199
|
5
|
-
collections_cache-0.1.3.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
6
|
-
collections_cache-0.1.3.dist-info/RECORD,,
|
File without changes
|
File without changes
|