Skip to content

Commit

Permalink
reset database cache
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian-B committed Dec 3, 2024
1 parent aad2544 commit b30e02c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ class BufferDatabase(BaseDatabase):

__slots__ = ()

@classmethod
def reset_db(cls, segment_number: int,
read_only: Optional[bool] = None) -> "BufferDatabase":
"""
Retrieves a NeoBufferDatabase for this segment.
"""
database_file = cls.reset_file(segment_number)
return BufferDatabase(database_file, read_only)

def clear_recording_region(
self, x: int, y: int, p: int, region: int) -> bool:
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,15 @@ def __init__(self, provenance_data_path: Optional[str] = None):
super().__init__(provenance_data_path, read_only=True,
row_factory=None, text_factory=None)

@classmethod
def reset_db(cls, segment_number: int,
read_only: Optional[bool] = None) -> "ProvenanceReader":
"""
Retrieves a NeoBufferDatabase for this segment.
"""
database_file = cls.reset_file(segment_number)
return ProvenanceReader(database_file, read_only)

def run_query(self, query: str, params: Iterable[_SqliteTypes] = ()
) -> List[Sequence[_SqliteTypes]]:
"""
Expand Down
13 changes: 12 additions & 1 deletion spinn_front_end_common/utilities/base_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import os
import sqlite3
import time
from typing import Optional, Union
from typing import Dict, Optional, Union
from typing_extensions import TypeAlias
from spinn_front_end_common.data import FecDataView
from spinn_front_end_common.utilities.sqlite_db import SQLiteDB
Expand All @@ -25,11 +25,14 @@
_SECONDS_TO_MICRO_SECONDS_CONVERSION = 1000
_SqliteTypes: TypeAlias = Union[str, int, float, bytes, None]

reset_cache: Dict[int, str] = {}


def _timestamp():
return int(time.time() * _SECONDS_TO_MICRO_SECONDS_CONVERSION)



class BaseDatabase(SQLiteDB):
"""
Specific implementation of the Database for SQLite 3.
Expand Down Expand Up @@ -65,6 +68,14 @@ def __init__(self, database_file: Optional[str] = None, *,
super().__init__(
self._database_file, read_only=read_only, row_factory=row_factory,
text_factory=text_factory, ddl_file=_DDL_FILE)
reset = FecDataView.get_reset_number()
if (reset not in reset_cache or
reset_cache[reset] != database_file):
reset_cache[reset] = database_file

@classmethod
def reset_file(cls, reset_number) -> str:
return reset_cache[reset_number]

@classmethod
def default_database_file(cls) -> str:
Expand Down

0 comments on commit b30e02c

Please sign in to comment.