How dev-mohammed/caching-queries works
Main Components
• Laravel Application Environment: Represent the Laravel application that will integrate this package.
• Service Provider Component: Highlight the CacheBuilderServiceProvider (located under the Database directory) that registers the custom cache functionality with Laravel.
• Custom Query Cache Components:
• CacheBuilder: This is responsible for setting up the caching logic.
• CacheQueryBuilder: A trait meant to be used by Laravel models, which overrides or extends the native query execution via the runSelect method to check and store cached results.
• ClearBuilderCache: A command that flushes the custom cache store.
• Configuration: The config file (Database/config/cachebuilder.php) used to enable/disable caching and set caching times.
• External Dependencies: Indicate that the package integrates with Barryvdh's DebugBar (for visibility of duplicate queries) and the underlying Laravel database and cache systems.
Out Relationships and Interactions
• Within the application, any model that includes the CacheQueryBuilder trait (illustrated as “Model using CacheQueryBuilder”) will have its select query operations intercepted.
• The overridden runSelect method in the custom query builder leverages the CacheBuilder logic to check for an existing cache (using SQL and bindings as keys) before executing the query. Indicate a bi-directional data flow between “Model/Query Execution” and “CacheBuilder Logic.”
Specify Architectural Patterns and Design Principles
• Separation of Concerns: Each component is responsible for a distinct functionality (service provider for registration, trait for query overriding, command for cache clearing).
• “Plug-in” nature of the package: It integrates seamlessly into an existing Laravel application and leverages extension points (e.g., the service provider registration and traits in models).
• Clearly demonstrate the overridden behavior: The custom CacheQueryBuilder trait intercepts select queries to implement caching (avoid duplicate executions) by checking against a custom cache store.
Specific Technologies and Frameworks
• Laravel Framework: Represent its core as the environment in which this package operates.
• Custom Cache Driver: Shown as part of the package’s implementation (and noted in the README, suggesting integration with Laravel’s cache system).