Skip to content

Commit

Permalink
Merge pull request #240 from Steinbeck-Lab/fix-limited-time-cache
Browse files Browse the repository at this point in the history
fix: all the values caches are set to expire after 2 days.
  • Loading branch information
CS76 authored Sep 10, 2024
2 parents d05776c + 847137f commit 1d14d76
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 19 deletions.
18 changes: 9 additions & 9 deletions app/Console/Commands/DashWidgetsRefresh.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,49 +32,49 @@ public function handle()
// Cache::flush();

// Create the cache for all DashboardStats widgets
Cache::rememberForever('stats.collections', function () {
Cache::remember('stats.collections', 172800, function () {
return DB::table('collections')->selectRaw('count(*)')->get()[0]->count;
});
$this->info('Cache for collections refreshed.');

Cache::rememberForever('stats.citations', function () {
Cache::remember('stats.citations', 172800, function () {
return DB::table('citations')->selectRaw('count(*)')->get()[0]->count;
});
$this->info('Cache for citations refreshed.');

Cache::rememberForever('stats.organisms', function () {
Cache::remember('stats.organisms', 172800, function () {
return DB::table('organisms')->selectRaw('count(*)')->get()[0]->count;
});
$this->info('Cache for organisms refreshed.');

Cache::rememberForever('stats.geo_locations', function () {
Cache::remember('stats.geo_locations', 172800, function () {
return DB::table('geo_locations')->selectRaw('count(*)')->get()[0]->count;
});
$this->info('Cache for geo locations refreshed.');

Cache::rememberForever('stats.reports', function () {
Cache::remember('stats.reports', 172800, function () {
return DB::table('reports')->selectRaw('count(*)')->get()[0]->count;
});
$this->info('Cache for reports refreshed.');

// Create the cache for all DashboardStatsMid widgets

Cache::rememberForever('stats.molecules.non_stereo', function () {
Cache::remember('stats.molecules.non_stereo', 172800, function () {
return DB::table('molecules')->selectRaw('count(*)')->whereRaw('has_stereo=false and is_parent=false')->get()[0]->count;
});
$this->info('Cache for molecules non-stereo refreshed.');

Cache::rememberForever('stats.molecules.stereo', function () {
Cache::remember('stats.molecules.stereo', 172800, function () {
return DB::table('molecules')->selectRaw('count(*)')->whereRaw('has_stereo=true')->get()[0]->count;
});
$this->info('Cache for molecules stereo refreshed.');

Cache::rememberForever('stats.molecules.parent', function () {
Cache::remember('stats.molecules.parent', 172800, function () {
return DB::table('molecules')->selectRaw('count(*)')->whereRaw('has_stereo=false and is_parent=true')->get()[0]->count;
});
$this->info('Cache for molecules parent refreshed.');

Cache::rememberForever('stats.molecules', function () {
Cache::remember('stats.molecules', 172800, function () {
return DB::table('molecules')->selectRaw('count(*)')->whereRaw('active=true and NOT (is_parent=true AND has_variants=true)')->get()[0]->count;
});
$this->info('Cache for molecules refreshed.');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ protected function getStats(): array
return [
// Commented is the model query that we can use in case we decide not to use app level caching as the app scales up.

// Stat::make('Entries', Cache::rememberForever('stats.collections'.$this->record->id.'entries.count', function () {
// Stat::make('Entries', Cache::remember('stats.collections'.$this->record->id.'entries.count', 172800, function () {
// return DB::table('entries')->selectRaw('count(*)')->whereRaw('collection_id='.$this->record->id)->get()[0]->count;
// }))
// ->description('Total count')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ class MoleculeStats extends BaseWidget
protected function getStats(): array
{
return [
Stat::make('Total Organisms', Cache::rememberForever('stats.molecules'.$this->record->id.'organisms.count', function () {
Stat::make('Total Organisms', Cache::remember('stats.molecules'.$this->record->id.'organisms.count', 172800, function () {
return DB::table('molecule_organism')->selectRaw('count(*)')->whereRaw('molecule_id='.$this->record->id)->get()[0]->count;
})),
Stat::make('Total Geo Locations', Cache::rememberForever('stats.molecules'.$this->record->id.'geo_locations.count', function () {
Stat::make('Total Geo Locations', Cache::remember('stats.molecules'.$this->record->id.'geo_locations.count', 172800, function () {
return DB::table('geo_location_molecule')->selectRaw('count(*)')->whereRaw('molecule_id='.$this->record->id)->get()[0]->count;
})),
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ class OrganismStats extends BaseWidget
protected function getStats(): array
{
return [
Stat::make('Total Molecules', Cache::rememberForever('stats.organisms'.$this->record->id.'molecules.count', function () {
Stat::make('Total Molecules', Cache::remember('stats.organisms'.$this->record->id.'molecules.count', 172800, function () {
return DB::table('molecule_organism')->selectRaw('count(*)')->whereRaw('organism_id='.$this->record->id)->get()[0]->count;
})),
Stat::make('Total Geo Locations', Cache::rememberForever('stats.organisms'.$this->record->id.'geo_locations.count', function () {
Stat::make('Total Geo Locations', Cache::remember('stats.organisms'.$this->record->id.'geo_locations.count', 172800, function () {
return DB::table('molecule_organism')->selectRaw('count(*)')->whereRaw('organism_id='.$this->record->id)->Join('geo_location_molecule', 'molecule_organism.molecule_id', '=', 'geo_location_molecule.molecule_id')->get()[0]->count;
})),
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class MolecularEntityController extends Controller
{
public function moleculeSchema(Request $request, $identifier)
{
$molecule = Cache::rememberForever('molecules.'.$identifier, function () use ($identifier) {
$molecule = Cache::remember('molecules.'.$identifier, 172800, function () use ($identifier) {
return Molecule::where('identifier', $identifier)->first();
});

Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/MoleculeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function __invoke(Request $request, $id)
$id .= '.0';
}

$molecule = Cache::rememberForever('molecules.'.$id, function () use ($id) {
$molecule = Cache::remember('molecules.'.$id, 172800, function () use ($id) {
return Molecule::where('identifier', $id)->first();
});

Expand Down
2 changes: 1 addition & 1 deletion app/Livewire/DataSources.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class DataSources extends Component

public function mount()
{
$this->collections = Cache::rememberForever('collections', function () {
$this->collections = Cache::remember('collections', 172800, function () {
return Collection::where('promote', true)->orderBy('sort_order')->take(10)->get(['title', 'image'])->toArray();
});
}
Expand Down
2 changes: 1 addition & 1 deletion app/Livewire/MoleculeDetails.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function rendered()
$_molecule = Cache::get('molecules.'.$id);
if (! $_molecule->relationLoaded('properties')) {
Cache::forget('molecules.'.$id);
Cache::rememberForever('molecules.'.$id, function () use ($molecule) {
Cache::remember('molecules.'.$id, 172800, function () use ($molecule) {
$molecule['schema'] = $molecule->getSchema();

return $molecule;
Expand Down
2 changes: 1 addition & 1 deletion app/Livewire/RecentMolecules.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class RecentMolecules extends Component
public function render()
{
return view('livewire.recent-molecules', [
'molecules' => Cache::rememberForever('molecules.recent', function () {
'molecules' => Cache::remember('molecules.recent', 172800, function () {
return Molecule::where('is_parent', false)->where('active', true)->where('name', '!=', null)->where('annotation_level', '=', 5)->orderByDesc('updated_at')->paginate($this->size);
}),
]);
Expand Down

0 comments on commit 1d14d76

Please sign in to comment.