Skip to content

SamratEmily/samrat-website-cache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

7 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Samrat Website Cache

WordPress PHP License Version

A powerful and lightweight caching plugin for WordPress that dramatically improves website performance through intelligent page caching and code minification.

Samrat Website Cache Banner

✨ Features

πŸš€ Page Caching

  • Stores rendered pages as static HTML files
  • Serves cached content before WordPress loads for maximum speed
  • Configurable cache expiry from 1 hour to 1 week
  • Automatic cache invalidation on content updates

πŸ“¦ Minification

  • HTML Minification - Removes unnecessary whitespace and comments
  • CSS Minification - Minifies inline <style> blocks
  • JavaScript Minification - Minifies inline <script> blocks
  • Safe minification that preserves <pre>, <code>, and <textarea> content

βš™οΈ Smart Exclusions

  • Exclude specific URLs with wildcard support
  • Cookie-based exclusions (great for WooCommerce)
  • Automatic exclusions for:
    • Admin pages
    • AJAX requests
    • REST API requests
    • Search results
    • 404 pages
    • Preview pages
    • Password-protected posts

πŸ›’ WooCommerce Compatible

Pre-configured exclusions for:

  • /cart/
  • /checkout/
  • /my-account/
  • Cart cookies (prevents caching when items in cart)

🎨 Modern Admin Interface

  • Beautiful, responsive settings page
  • Real-time cache statistics
  • One-click cache clearing
  • Admin bar integration for quick access

πŸ“‹ Requirements

  • WordPress 5.0 or higher
  • PHP 7.4 or higher

πŸ”§ Installation

From WordPress Admin

  1. Go to Plugins β†’ Add New
  2. Search for "Samrat Website Cache"
  3. Click Install Now then Activate
  4. Navigate to Website Cache β†’ Settings to configure

Manual Installation

  1. Download the latest release
  2. Upload the samrat-website-cache folder to /wp-content/plugins/
  3. Activate through the Plugins menu
  4. Configure at Website Cache β†’ Settings

⚑ Quick Start

The plugin works out of the box with sensible defaults:

Setting Default
Page Cache βœ… Enabled
Cache for Logged-in Users ❌ Disabled
Cache Expiry 24 hours
HTML Minification ❌ Disabled
CSS Minification ❌ Disabled
JS Minification ❌ Disabled

For most websites, simply activate and you're done!

🎯 Configuration

Page Cache Settings

Option Description
Enable Page Cache Toggle page caching on/off
Cache for Logged-in Users Enable caching for authenticated users (not recommended for dynamic content)
Cache Expiry Time How long to keep cached pages (1 hour - 1 week)

Minification Settings

Option Description
Minify HTML Remove whitespace and comments from HTML
Minify CSS Minify inline CSS styles
Minify JavaScript Minify inline JavaScript code

Cache Exclusions

Exclude Pages - Enter URL paths to exclude (one per line):

/cart/
/checkout/
/my-account/
/api/*
/contact/

Exclude Cookies - Skip caching when these cookies exist:

woocommerce_cart_hash
woocommerce_items_in_cart
custom_session_cookie

πŸ” Verifying Cache is Working

Method 1: View Page Source

Look for this comment at the bottom of your HTML:

<!-- Cached by Samrat Website Cache on 2024-01-15 10:30:00 -->

Method 2: Check Response Headers

X-Samrat-Cache: HIT
X-Samrat-Cache-Time: 2024-01-15 10:30:00

Method 3: Admin Dashboard

Visit Website Cache β†’ Settings to see:

  • Number of cached pages
  • Total cache size
  • Cache status (Active/Inactive)

πŸ—‘οΈ Clearing Cache

Manual Clear

  1. Settings Page - Click "Clear All Cache" button
  2. Admin Bar - Click "Cache β†’ Clear Cache"
  3. Clear Cache Page - Visit Website Cache β†’ Clear Cache

Automatic Clear

Cache automatically clears when:

  • Posts/pages are updated or deleted
  • Theme is changed
  • Plugins are activated/deactivated
  • WordPress core is updated
  • WooCommerce stock changes

πŸ“ File Structure

samrat-website-cache/
β”œβ”€β”€ assets/
β”‚   β”œβ”€β”€ css/
β”‚   β”‚   └── admin.css          # Admin styles
β”‚   └── js/
β”‚       └── admin.js           # Admin JavaScript
β”œβ”€β”€ cache/                      # Cached HTML files
β”œβ”€β”€ includes/
β”‚   β”œβ”€β”€ AdminMenu.php          # Admin menu & settings
β”‚   └── CacheHandler.php       # Core caching logic
β”œβ”€β”€ README.md                   # This file
β”œβ”€β”€ readme.txt                  # WordPress.org readme
└── samrat-website-cache.php   # Main plugin file

πŸ”Œ Hooks & Filters

Actions

// Fires after cache is cleared
do_action('samrat_cache_cleared');

// Fires after a single page cache is cleared
do_action('samrat_cache_page_cleared', $post_id);

Filters

// Modify cache settings
$settings = apply_filters('samrat_cache_settings', $settings);

// Modify excluded pages
$excluded = apply_filters('samrat_cache_excluded_pages', $excluded_pages);

// Modify cache key
$cache_key = apply_filters('samrat_cache_key', $cache_key, $url);

πŸ› Troubleshooting

Pages not being cached

  1. Check if page caching is enabled in settings
  2. Ensure you're not logged in (unless "Cache for Logged-in Users" is enabled)
  3. Check if the page URL is in exclusion list
  4. Verify no excluded cookies are present
  5. Clear cache and try again

Styling/Layout issues

  1. Disable HTML minification
  2. Disable CSS minification
  3. Clear cache after changes
  4. Check for JavaScript errors in console

Cache not clearing

  1. Check file permissions on /cache/ directory
  2. Ensure WordPress has write access
  3. Try clearing manually via FTP/file manager

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“„ License

This project is licensed under the GPLv2 or later - see the LICENSE file for details.

πŸ‘¨β€πŸ’» Author

Samrat Hossen

πŸ™ Acknowledgments

  • WordPress Plugin Development Team
  • The WordPress community for continuous support and feedback

⭐ If you find this plugin helpful, please consider giving it a star on GitHub!

About

This WordPress plugin is build for website cache

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors