mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-24 13:51:14 -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)
|
||||
});
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -121,4 +121,31 @@ export const queryKeys = {
|
||||
['ride-models', 'rides', modelId, limit] as const,
|
||||
statistics: (modelId: string) => ['ride-models', 'statistics', modelId] as const,
|
||||
},
|
||||
|
||||
// Settings queries
|
||||
settings: {
|
||||
publicNovu: () => ['public-novu-settings'] as const,
|
||||
},
|
||||
|
||||
// Stats queries
|
||||
stats: {
|
||||
coaster: (rideId: string) => ['coaster-stats', rideId] as const,
|
||||
},
|
||||
|
||||
// Blog queries
|
||||
blog: {
|
||||
post: (slug: string) => ['blog-post', slug] as const,
|
||||
viewIncrement: (slug: string) => ['blog-view-increment', slug] as const,
|
||||
},
|
||||
|
||||
// Entity name queries (for PhotoManagementDialog)
|
||||
entities: {
|
||||
name: (entityType: string, entityId: string) => ['entity-name', entityType, entityId] as const,
|
||||
},
|
||||
|
||||
// Security queries
|
||||
security: {
|
||||
emailChangeStatus: () => ['email-change-status'] as const,
|
||||
sessions: () => ['my-sessions'] as const,
|
||||
},
|
||||
} as const;
|
||||
|
||||
Reference in New Issue
Block a user