brighter-trading/markdown/DataCache.md

109 lines
2.3 KiB
Markdown

### cache_exists
```plantuml
@startuml
start
if (Is cache exists for key?) then (yes)
:Return True;
else (no)
:Return False;
endif
stop
@enduml
```
### update_candle_cache
```plantuml
@startuml
start
:Combine new records with existing cache;
:Drop duplicates;
:Set modified records to cache;
stop
@enduml
```
### set_cache
```plantuml
@startuml
start
if (Do not overwrite data flag is set?) then (yes)
if (Cache key already exists?) then (yes)
stop
else (no)
:Assign data to cache with key;
endif
else (no)
:Assign data to cache with key;
endif
stop
@enduml
```
### update_cached_dict
```plantuml
@startuml
start
:Update dictionary in cache with new data;
stop
@enduml
```
### get_cache
```plantuml
@startuml
start
if (Cache key exists?) then (yes)
:Return requested data;
else (no)
:Print warning message;
:Return None;
endif
stop
@enduml
```
### get_records_since
This diagram represents the flow of the get_records_since function. It starts by checking if the records exist in the cache. If they do, the function retrieves them from the cache. If not, it requests the records from the database and stores them in the cache.
The diagram then checks if the retrieved records satisfy the query requirements. If they do, the function proceeds. Otherwise, it gets additional records from the database and updates the cache if necessary.
Next, the diagram checks if the records are up-to-date. If they are, the function proceeds. Otherwise, it updates the database table and retrieves additional records if needed.
Finally, the function creates a timestamp, filters the records based on the timestamp, and returns the result.
```plantuml
@startuml
start
if (Cache exists?) then (yes)
:Retrieve records from cache;
:Set records;
else (no)
:Request records from DB;
:Set records;
:Store records in cache;
endif
if (Records satisfy query?) then (yes)
:Query satisfied;
else (no)
:Get additional records from DB;
if (Additional records received?) then (yes)
:Update cache;
endif
endif
if (Records up-to-date?) then (yes)
:Query up-to-date;
else (no)
:Update DB table;
if (Additional records received?) then (yes)
:Update cache;
endif
endif
:Create timestamp;
:Filter records;
stop
@enduml
```