collections-cache 0.2.3__py3-none-any.whl → 0.2.4.dev20250303__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 +28 -14
- {collections_cache-0.2.3.dist-info → collections_cache-0.2.4.dev20250303.dist-info}/METADATA +1 -1
- collections_cache-0.2.4.dev20250303.dist-info/RECORD +6 -0
- collections_cache-0.2.3.dist-info/RECORD +0 -6
- {collections_cache-0.2.3.dist-info → collections_cache-0.2.4.dev20250303.dist-info}/LICENSE +0 -0
- {collections_cache-0.2.3.dist-info → collections_cache-0.2.4.dev20250303.dist-info}/WHEEL +0 -0
| @@ -14,15 +14,21 @@ class Collection_Cache: | |
| 14 14 | 
             
                    self.collection_dir         = path.join("./Collections", self.collection_name)
         | 
| 15 15 | 
             
                    self.databases_list         = []
         | 
| 16 16 | 
             
                    self.keys_databases         = {}
         | 
| 17 | 
            +
             | 
| 17 18 | 
             
                    # Init methods
         | 
| 18 19 | 
             
                    self.create_collection()
         | 
| 19 20 | 
             
                    self.get_all_databases()
         | 
| 20 21 |  | 
| 21 | 
            -
                def  | 
| 22 | 
            -
                     | 
| 23 | 
            -
             | 
| 24 | 
            -
                         | 
| 25 | 
            -
                         | 
| 22 | 
            +
                def configure_connection(self, conn):
         | 
| 23 | 
            +
                    conn.executescript("""
         | 
| 24 | 
            +
                        PRAGMA auto_vacuum = FULL;
         | 
| 25 | 
            +
                        PRAGMA journal_mode = WAL;
         | 
| 26 | 
            +
                        PRAGMA synchronous = NORMAL;
         | 
| 27 | 
            +
                        PRAGMA wal_autocheckpoint = 1000;
         | 
| 28 | 
            +
                        PRAGMA cache_size = -2000;
         | 
| 29 | 
            +
                        PRAGMA temp_store = MEMORY;
         | 
| 30 | 
            +
                        PRAGMA optimize;
         | 
| 31 | 
            +
                    """)
         | 
| 26 32 |  | 
| 27 33 | 
             
                def initialize_databases(self, db_path):
         | 
| 28 34 | 
             
                    conn = sqlite3.connect(db_path)
         | 
| @@ -35,9 +41,17 @@ class Collection_Cache: | |
| 35 41 | 
             
                    """)
         | 
| 36 42 | 
             
                    conn.close()
         | 
| 37 43 |  | 
| 44 | 
            +
                def create_collection(self):
         | 
| 45 | 
            +
                    makedirs(self.collection_dir, exist_ok=True)
         | 
| 46 | 
            +
             | 
| 47 | 
            +
                    for core in range(self.cpu_cores):
         | 
| 48 | 
            +
                        db_path = path.join(self.collection_dir, f"database_{core}.db")
         | 
| 49 | 
            +
                        self.initialize_databases(db_path)
         | 
| 50 | 
            +
             | 
| 38 51 | 
             
                def get_all_databases(self):
         | 
| 39 52 | 
             
                    with scandir(self.collection_dir) as contents:
         | 
| 40 53 | 
             
                        self.databases_list = [path.join(self.collection_dir, content.name) for content in contents]
         | 
| 54 | 
            +
             | 
| 41 55 | 
             
                    with Pool(self.cpu_cores) as pool:
         | 
| 42 56 | 
             
                        self.keys_databases = dict(chain.from_iterable(pool.map(self.get_all_keys, self.databases_list)))
         | 
| 43 57 |  | 
| @@ -62,6 +76,7 @@ class Collection_Cache: | |
| 62 76 | 
             
                        conn.commit()
         | 
| 63 77 | 
             
                        conn.close()
         | 
| 64 78 | 
             
                        self.add_to_keys_database(key, database_to_insert)
         | 
| 79 | 
            +
             | 
| 65 80 | 
             
                    else:
         | 
| 66 81 | 
             
                        database_to_update = self.keys_databases[key]
         | 
| 67 82 | 
             
                        conn = sqlite3.connect(database_to_update)
         | 
| @@ -73,6 +88,7 @@ class Collection_Cache: | |
| 73 88 |  | 
| 74 89 | 
             
                def set_multi_keys(self, keys_and_values: dict[str, any]):
         | 
| 75 90 | 
             
                    """Experimental. Set multiple keys and values at the same time."""
         | 
| 91 | 
            +
             | 
| 76 92 | 
             
                    with Thread(self.cpu_cores) as thread:
         | 
| 77 93 | 
             
                        thread.map(lambda kv: self.set_key(kv[0], kv[1]), keys_and_values.items())
         | 
| 78 94 |  | 
| @@ -81,11 +97,13 @@ class Collection_Cache: | |
| 81 97 |  | 
| 82 98 | 
             
                def delete_to_keys_database(self, key):
         | 
| 83 99 | 
             
                    """Removes the key from the dictionary of stored keys"""
         | 
| 100 | 
            +
             | 
| 84 101 | 
             
                    if key in self.keys_databases:
         | 
| 85 102 | 
             
                        del self.keys_databases[key]
         | 
| 86 103 |  | 
| 87 104 | 
             
                def get_key(self, key: str):
         | 
| 88 105 | 
             
                    """Used to obtain the value stored by the key"""
         | 
| 106 | 
            +
             | 
| 89 107 | 
             
                    try:
         | 
| 90 108 | 
             
                        database_to_search = self.keys_databases[key]
         | 
| 91 109 | 
             
                        conn = sqlite3.connect(database_to_search)
         | 
| @@ -95,11 +113,13 @@ class Collection_Cache: | |
| 95 113 | 
             
                        result = cursor.fetchall()
         | 
| 96 114 | 
             
                        conn.close()
         | 
| 97 115 | 
             
                        return pickle.loads(result[0][0])
         | 
| 116 | 
            +
             | 
| 98 117 | 
             
                    except Exception as error:
         | 
| 99 118 | 
             
                        return error
         | 
| 100 119 |  | 
| 101 120 | 
             
                def delete_key(self, key: str):
         | 
| 102 121 | 
             
                    """Used to delete the value stored by the key"""
         | 
| 122 | 
            +
             | 
| 103 123 | 
             
                    try:
         | 
| 104 124 | 
             
                        database_to_delete = self.keys_databases[key]
         | 
| 105 125 | 
             
                        conn = sqlite3.connect(database_to_delete)
         | 
| @@ -109,20 +129,14 @@ class Collection_Cache: | |
| 109 129 | 
             
                        conn.commit()
         | 
| 110 130 | 
             
                        conn.close()
         | 
| 111 131 | 
             
                        self.delete_to_keys_database(key)
         | 
| 132 | 
            +
             | 
| 112 133 | 
             
                    except KeyError:
         | 
| 113 134 | 
             
                        return f"Key '{key}' not found."
         | 
| 135 | 
            +
             | 
| 114 136 | 
             
                    except Exception as error:
         | 
| 115 137 | 
             
                        return error
         | 
| 116 138 |  | 
| 117 | 
            -
                 | 
| 118 | 
            -
                    conn.execute("PRAGMA auto_vacuum = FULL;")
         | 
| 119 | 
            -
                    conn.execute("PRAGMA journal_mode = WAL;")
         | 
| 120 | 
            -
                    conn.execute("PRAGMA synchronous = NORMAL;")
         | 
| 121 | 
            -
                    conn.execute("PRAGMA wal_autocheckpoint = 1000;")
         | 
| 122 | 
            -
                    conn.execute("PRAGMA cache_size = -2000;")
         | 
| 123 | 
            -
                    conn.execute("PRAGMA temp_store = MEMORY;")
         | 
| 124 | 
            -
                    conn.execute("PRAGMA optimize;")
         | 
| 125 | 
            -
             | 
| 139 | 
            +
                
         | 
| 126 140 | 
             
                def keys(self):
         | 
| 127 141 | 
             
                    """Returns all stored keys"""
         | 
| 128 142 | 
             
                    return list(self.keys_databases.keys())
         | 
    
        {collections_cache-0.2.3.dist-info → collections_cache-0.2.4.dev20250303.dist-info}/METADATA
    RENAMED
    
    | @@ -1,6 +1,6 @@ | |
| 1 1 | 
             
            Metadata-Version: 2.1
         | 
| 2 2 | 
             
            Name: collections-cache
         | 
| 3 | 
            -
            Version: 0.2. | 
| 3 | 
            +
            Version: 0.2.4.dev20250303
         | 
| 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=VNCzP4fZSL-BUXDVqwa9aXfU4JWJHMKNei5v15aua6E,5109
         | 
| 3 | 
            +
            collections_cache-0.2.4.dev20250303.dist-info/LICENSE,sha256=RAIL-FmXSiNRgyiVlfhm2SvVI4XDVsN0jDt9207SJ8o,1168
         | 
| 4 | 
            +
            collections_cache-0.2.4.dev20250303.dist-info/METADATA,sha256=38BhwUcGyowiHRYdzbU0VaABRXLUbl8_d1Rn8cCgX3A,3420
         | 
| 5 | 
            +
            collections_cache-0.2.4.dev20250303.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
         | 
| 6 | 
            +
            collections_cache-0.2.4.dev20250303.dist-info/RECORD,,
         | 
| @@ -1,6 +0,0 @@ | |
| 1 | 
            -
            collections_cache/__init__.py,sha256=uUp8lhp-HnZRumnU_8MT6qVq95t0pOzn7oLW7ARbnvc,48
         | 
| 2 | 
            -
            collections_cache/collections_cache.py,sha256=HWTwxrXsMc3sRcsrRkLugp_QtbBASvem6kBQShMEYO4,5133
         | 
| 3 | 
            -
            collections_cache-0.2.3.dist-info/LICENSE,sha256=RAIL-FmXSiNRgyiVlfhm2SvVI4XDVsN0jDt9207SJ8o,1168
         | 
| 4 | 
            -
            collections_cache-0.2.3.dist-info/METADATA,sha256=_NbnncpG10Jlw4cwh_p4TgaVD0k18d7AWF07VwyUt3Y,3408
         | 
| 5 | 
            -
            collections_cache-0.2.3.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
         | 
| 6 | 
            -
            collections_cache-0.2.3.dist-info/RECORD,,
         | 
| 
            File without changes
         | 
| 
            File without changes
         |