Skip to content
This repository has been archived by the owner on Nov 12, 2020. It is now read-only.

Commit

Permalink
Updated readme and changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
Kniest Jordan authored and Kniest Jordan committed Jan 7, 2018
1 parent e5a6544 commit 37b6405
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 21 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright 2017 Jordan Kniest
Copyright Jordan Kniest

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
Expand Down
6 changes: 6 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [1.0.3] - 2018-01-07
### Changed
- GET parameters are now considered in the cache generation
- Offical PHP 7.2 support

## [1.0.2] - 2017-11-21
### Changed
- Sites are not being cached if they do not have a 200 status code
Expand All @@ -21,3 +26,4 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

[1.0.1]: https://github.com/jkniest/HTMLCache/compare/1.0.0...1.0.1
[1.0.2]: https://github.com/jkniest/HTMLCache/compare/1.0.1...1.0.2
[1.0.3]: https://github.com/jkniest/HTMLCache/compare/1.0.2...1.0.3
30 changes: 10 additions & 20 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ This package is made for you if you have a lot of static pages (or pages that do

And it is highly customizable: You can even cache the same page for every user different, allowing that you can cache for example their account page or dashboard without worrying that another user can see these cached pages.

__One benefit against much other html caches:__ It will also cache the pages based on language, and (optionally) user id. And if there are special cases (for example a special GET-parameter) that needs to be used to generate multiple versions of the same page, the middleware can be easily modified.
__One benefit against much other html caches:__ It will also cache the pages based on language, and (optionally) user id. And if there are special cases (for example a specific session value) that needs to be used to generate multiple versions of the same page, the middleware can be easily modified.

---

Expand Down Expand Up @@ -131,7 +131,7 @@ In a few cases the pages will not be cached:

## Configuration

You can nearly configure anything inside the `.env` file.
You can configure nearly anything inside the `.env` file.

### Enable / Disable cache

Expand Down Expand Up @@ -191,21 +191,21 @@ This will create a new file in your project: `config/htmlcache.php`. There you c

## Clear cache

The html cache package uses the default laravel cache helpers. So you simple run the artisan command to clear the cache:
The html cache package uses the default laravel cache helpers. So you can run the artisan command to clear the cache:

```shell
php artisan cache:clear
```

This will remove every cached version of this plugin (and also of everything else). It is recommended to put this in your deployment workflow (for example in the deployment script in forge or as an deployment hook in envoyer)
This will remove every cached version of this plugin (and also everything else). It is recommended to put this in your deployment workflow (for example in the deployment script in forge or as a deployment hook in envoyer)

---

## Override middlware

It is possible to override the middleware. So you could override the cache-key generation. In this short tutorial we will add another field to the cache key generation (the post id).
It is possible to override the middleware. So you could override the cache-key generation. In this short tutorial we will add another field to the cache key generation (the current weekday).

Let's say you have a forum and you can access each page with a get parameter. For example: `http://my-forum.dev?page=3`. In the default implementation all pages would share the same cached results (which means that the pagination isn't working anymore).
Let's say you have a dashboard and all data on this dashboard will only update every weekday. In the default implementation you would have to set a maximum cache time (for example 1 day) but you can't be sure that the cache was generated exactly on 0am.

The simplest solution would be to override the middleware and extends the cache-key generation.

Expand All @@ -232,10 +232,11 @@ Now we can override any methods. The method `getCacheKey` handles the generation
$prefix = config('htmlcache.prefix');
$locale = app()->getLocale();

$page = str_replace('/', '_', trim($page, '/'));
$page = md5(trim($page, '/'));

if (config('htmlcache.user_specific')) {
$id = Auth::check() ? Auth::id() : -1;

return "{$prefix}{$page}_{$locale}_{$id}";
}

Expand All @@ -250,9 +251,7 @@ Let's implement our own (in the HtmlCache middleware that we just created):
{
$key = parent::getCacheKey($page);

if (request('page') !== null) {
$key .= '_' . request('page');
}
$key .= date('D');

return $key;
}
Expand All @@ -273,18 +272,9 @@ Of course you can always override any other method (like the `Handle` method its

---

## Roadmap

These are features that are planned for to upcoming versions. If you have any suggestion please let me know via issues or e-mail me at `contact@jkniest.de`

### Version 1.1.0
- Add native pagination support (so that the page GET parameter will also be cached)

---

## License

Copyright 2017 Jordan Kniest
Copyright Jordan Kniest

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
Expand Down

0 comments on commit 37b6405

Please sign in to comment.