Skip to content

Commit

Permalink
Move cache keys to String to allow dynamic
Browse files Browse the repository at this point in the history
Update vatsim_utils dep
  • Loading branch information
Celeo committed Dec 13, 2024
1 parent 51c42d4 commit 0b99e9e
Show file tree
Hide file tree
Showing 10 changed files with 16 additions and 16 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vzdv-bot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ twilight-http = "0.15.4"
twilight-interactions = "0.15.2"
twilight-model = "0.15.4"
twilight-util = { version = "0.15.4", features = ["builder"] }
vatsim_utils = "0.5.2"
vatsim_utils = "0.5.3"
2 changes: 1 addition & 1 deletion vzdv-site/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ tower-http = { version = "0.5.2", features = ["fs", "timeout"] }
tower-sessions = "0.12.0"
tower-sessions-sqlx-store = { version = "0.13.0", features = ["sqlite"] }
uuid = { version = "1.10.0", features = ["v4", "fast-rng"] }
vatsim_utils = "0.5.2"
vatsim_utils = "0.5.3"
regex = "1.11.0"

[build-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion vzdv-site/src/endpoints/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -861,7 +861,7 @@ async fn page_activity_report_generate(
let user_info = user_info.unwrap();

// cache this endpoint's returned data for 6 hours
let cache_key = "ACTIVITY_REPORT";
let cache_key = "ACTIVITY_REPORT".to_string();
if let Some(cached) = state.cache.get(&cache_key) {
let elapsed = Instant::now() - cached.inserted;
if elapsed.as_secs() < 60 * 60 * 6 {
Expand Down
6 changes: 3 additions & 3 deletions vzdv-site/src/endpoints/airspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ async fn page_flights(
session: Session,
) -> Result<Html<String>, AppError> {
// cache this endpoint's returned data for 15 seconds
let cache_key = "ONLINE_FLIGHTS_FULL";
let cache_key = "ONLINE_FLIGHTS_FULL".to_string();
if let Some(cached) = state.cache.get(&cache_key) {
let elapsed = Instant::now() - cached.inserted;
if elapsed.as_secs() < 15 {
Expand Down Expand Up @@ -95,7 +95,7 @@ async fn page_weather(
session: Session,
) -> Result<Html<String>, AppError> {
// cache this endpoint's returned data for 5 minutes
let cache_key = "WEATHER_FULL";
let cache_key = "WEATHER_FULL".to_string();
if let Some(cached) = state.cache.get(&cache_key) {
let elapsed = Instant::now() - cached.inserted;
if elapsed.as_secs() < 300 {
Expand Down Expand Up @@ -305,7 +305,7 @@ async fn page_pilot_glance_data(
};

// cache this endpoint's returned data for 1 minute
let cache_key = "PILOT_GLANCE";
let cache_key = format!("PILOT_GLANCE-{airport}");
if let Some(cached) = state.cache.get(&cache_key) {
let elapsed = Instant::now() - cached.inserted;
if elapsed.as_secs() < 60 {
Expand Down
2 changes: 1 addition & 1 deletion vzdv-site/src/endpoints/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ async fn api_page_flights(
State(state): State<Arc<AppState>>,
) -> Result<Json<OnlineFlights>, AppError> {
// cache this endpoint's returned data for 15 seconds
let cache_key = "ONLINE_FLIGHTS";
let cache_key = "ONLINE_FLIGHTS".to_string();
if let Some(cached) = state.cache.get(&cache_key) {
let elapsed = Instant::now() - cached.inserted;
if elapsed.as_secs() < 15 {
Expand Down
8 changes: 4 additions & 4 deletions vzdv-site/src/endpoints/homepage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ async fn snippet_online_controllers(
State(state): State<Arc<AppState>>,
) -> Result<Html<String>, AppError> {
// cache this endpoint's returned data for 30 seconds
let cache_key = "ONLINE_CONTROLLERS";
let cache_key = "ONLINE_CONTROLLERS".to_string();
if let Some(cached) = state.cache.get(&cache_key) {
let elapsed = Instant::now() - cached.inserted;
if elapsed.as_secs() < 30 {
Expand All @@ -70,7 +70,7 @@ async fn snippet_online_controllers(

async fn snippet_weather(State(state): State<Arc<AppState>>) -> Result<Html<String>, AppError> {
// cache this endpoint's returned data for 5 minutes
let cache_key = "WEATHER_BRIEF";
let cache_key = "WEATHER_BRIEF".to_string();
if let Some(cached) = state.cache.get(&cache_key) {
let elapsed = Instant::now() - cached.inserted;
if elapsed.as_secs() < 300 {
Expand Down Expand Up @@ -117,7 +117,7 @@ async fn snippet_weather(State(state): State<Arc<AppState>>) -> Result<Html<Stri

async fn snippet_flights(State(state): State<Arc<AppState>>) -> Result<Html<String>, AppError> {
// cache this endpoint's returned data for 15 seconds
let cache_key = "ONLINE_FLIGHTS_HOMEPAGE";
let cache_key = "ONLINE_FLIGHTS_HOMEPAGE".to_string();
if let Some(cached) = state.cache.get(&cache_key) {
let elapsed = Instant::now() - cached.inserted;
if elapsed.as_secs() < 15 {
Expand Down Expand Up @@ -145,7 +145,7 @@ async fn snippet_flights(State(state): State<Arc<AppState>>) -> Result<Html<Stri

async fn snippet_cotm(State(state): State<Arc<AppState>>) -> Result<Html<String>, AppError> {
// cache this endpoint's returned data for 1 minute
let cache_key = "COTM";
let cache_key = "COTM".to_string();
if let Some(cached) = state.cache.get(&cache_key) {
let elapsed = Instant::now() - cached.inserted;
if elapsed.as_secs() < 60 {
Expand Down
2 changes: 1 addition & 1 deletion vzdv-site/src/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ pub struct AppState {
/// Loaded templates
pub templates: Environment<'static>,
/// Server-side cache for heavier-compute rendered templates
pub cache: Cache<&'static str, CacheEntry>,
pub cache: Cache<String, CacheEntry>,
}

/// Key for user info CRUD in session.
Expand Down
2 changes: 1 addition & 1 deletion vzdv-tasks/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ clap = { version = "4.5.1", features = ["derive"] }
log = "0.4.20"
sqlx = { version = "0.8.1", default-features = false, features = ["runtime-tokio", "sqlx-sqlite", "chrono"] }
tokio = { version = "1.36.0", features = ["full"] }
vatsim_utils = "0.5.2"
vatsim_utils = "0.5.3"
2 changes: 1 addition & 1 deletion vzdv/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ tower = "0.4.13"
tower-http = { version = "0.5.2", features = ["fs", "timeout"] }
tower-sessions = "0.12.0"
tower-sessions-sqlx-store = { version = "0.13.0", features = ["sqlite"] }
vatsim_utils = "0.5.2"
vatsim_utils = "0.5.3"
fern = { version = "0.6.2", features = ["colored"] }
humantime = "2.1.0"

0 comments on commit 0b99e9e

Please sign in to comment.