mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-24 15:11:12 -05:00
Implement cache management
This commit is contained in:
@@ -247,8 +247,82 @@ export function useQueryInvalidation() {
|
||||
* Invalidate model rides cache
|
||||
* Call this after ride changes
|
||||
*/
|
||||
invalidateModelRides: (modelId: string) => {
|
||||
queryClient.invalidateQueries({ queryKey: ['ride-models', 'rides', modelId] });
|
||||
invalidateModelRides: (modelId: string, limit?: number) => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: queryKeys.rideModels.rides(modelId, limit),
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Invalidate entity name cache
|
||||
* Call this after updating an entity's name
|
||||
*/
|
||||
invalidateEntityName: (entityType: string, entityId: string) => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: queryKeys.entities.name(entityType, entityId)
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Invalidate blog post cache
|
||||
* Call this after updating a blog post
|
||||
*/
|
||||
invalidateBlogPost: (slug: string) => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: queryKeys.blog.post(slug)
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Invalidate coaster stats cache
|
||||
* Call this after updating ride statistics
|
||||
*/
|
||||
invalidateCoasterStats: (rideId: string) => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: queryKeys.stats.coaster(rideId)
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Invalidate security queries
|
||||
* Call this after security-related changes (email, sessions)
|
||||
*/
|
||||
invalidateSecurityQueries: () => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: queryKeys.security.emailChangeStatus()
|
||||
});
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: queryKeys.security.sessions()
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Smart invalidation for related entities
|
||||
* Invalidates entity detail, photos, reviews, and name cache
|
||||
* Call this after any entity update
|
||||
*/
|
||||
invalidateRelatedEntities: (entityType: string, entityId: string) => {
|
||||
// Invalidate the entity itself
|
||||
if (entityType === 'park') {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: queryKeys.parks.detail(entityId)
|
||||
});
|
||||
} else if (entityType === 'ride') {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: queryKeys.rides.detail('', entityId)
|
||||
});
|
||||
}
|
||||
|
||||
// Invalidate photos, reviews, and entity name
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: queryKeys.photos.entity(entityType, entityId)
|
||||
});
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: queryKeys.reviews.entity(entityType as 'park' | 'ride', entityId)
|
||||
});
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: queryKeys.entities.name(entityType, entityId)
|
||||
});
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user