-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewrote/added the majority of the v2 docs
Fixed bug where: when clicking a menu item, you didn't get scrolled back to the top Added basic scroll to top button Signed-off-by: Sam Parton <[email protected]>
- Loading branch information
1 parent
830876f
commit e3736cc
Showing
32 changed files
with
3,074 additions
and
320 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,7 @@ | ||
<?php | ||
|
||
return [ | ||
|
||
'name' => 'Envuso', | ||
|
||
'cli_access' => 'envuso' | ||
|
||
'cli_access' => 'envuso', | ||
'default_version' => '2.0', | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,91 +1,83 @@ | ||
# Cache | ||
|
||
More info needed here. | ||
|
||
|
||
## Introduction | ||
|
||
Right now the cache implementation is quite basic and is based only on Redis. | ||
**Caching will only will only work if you have "redis : {enabled : true}" in your <code class="language-typescript">/src/Config/Database.ts</code> config file.** | ||
|
||
## Obtaining a cache instance | ||
|
||
You can use it directly via the container, or via static methods | ||
Right now the cache implementation is quite basic and is based only on Redis. | ||
|
||
```typescript | ||
import {Cache} from '@envuso/core/Cache'; | ||
import {resolve} from '@envuso/core/AppContainer'; | ||
|
||
Cache.set() | ||
resolve(Cache).set() | ||
``` | ||
**You must have the RedisServiceProvider added/loaded to the framework for Caching to work. This is added by default.** | ||
|
||
## Retrieving items from the cache | ||
|
||
All cache methods are async, so you will need to use .then() or await them to get the result. | ||
You can pass a second parameter to .get() to provide as the default value if the item does not exist in the cache. | ||
By default, the second parameter will return null | ||
|
||
```typescript | ||
const value = await Cache.get('some-key'); | ||
await Cache.get('some-key'); | ||
|
||
const nonExistentValue = await Cache.get('some-non-existent-value', 'woop'); | ||
// We can also pass a type, .get() uses generics. | ||
await Cache.get<string>('some-string-value'); | ||
|
||
console.log(nonExistentValue); // returns 'woop'; | ||
// We can pass an optional second parameter to use as a fall back. By default this value is null. | ||
await Cache.get('some-non-existent-value', 'woop'); // returns "woop" | ||
``` | ||
|
||
## Storing items in the cache | ||
|
||
#### Storing the item forever | ||
### Storing the item forever | ||
|
||
```typescript | ||
import {Cache} from '@envuso/core/Cache'; | ||
|
||
await Cache.put('some-key', 'some value'); | ||
``` | ||
|
||
#### adding an item that expires at x time | ||
### Adding an item that expires | ||
|
||
We can create a new DateTime instance and pass this as a third parameter to set the value to expire at x time. | ||
|
||
```typescript | ||
import {Cache} from '@envuso/core/Cache'; | ||
import {DateTime} from '@envuso/core/Common'; | ||
|
||
await Cache.put('some-key', 'some value', DateTime.now().addSeconds(20)); | ||
|
||
// 25 seconds later... | ||
setTimeout(async () => { | ||
console.log(await Cache.get('some-key')) // returns null | ||
}, 25 * 1000); | ||
await Cache.put('some-key', 'some value', DateTime.now().addHours(24)); | ||
// This value will no longer exist after 24 hours | ||
``` | ||
|
||
## Removing items from the cache | ||
|
||
```typescript | ||
import {Cache} from '@envuso/core/Cache'; | ||
|
||
await Cache.remove('some-key'); | ||
``` | ||
|
||
## check if item exists in cache | ||
|
||
.exists() will return true if the item exists, false if it does not exist. | ||
## Checking for existence | ||
|
||
```typescript | ||
import {Cache} from '@envuso/core/Cache'; | ||
|
||
await Cache.exists('some-key'); // returns true or false | ||
await Cache.has('some-key'); // returns boolean | ||
``` | ||
|
||
## retrieve and store | ||
## Retrieve and Store | ||
|
||
Sometimes we may want to store an item in the cache, but return a default if it doesn't. This is how .get() works. | ||
But... what if we want to store an item in the cache if it doesn't exist? | ||
.remember() will return the item from the cache if it exists, if it doesn't, it will add your item and then return it. | ||
|
||
When dealing with caching, we usually end up writing the same boilerplate: | ||
|
||
```typescript | ||
import {Cache} from '@envuso/core/Cache'; | ||
let data = await Cache.get('some-data', null); | ||
|
||
if (data) { | ||
return data; | ||
} | ||
|
||
data = 'some value'; | ||
|
||
await Cache.remember('some-key', () => await User.get(), DateTime.now().addSeconds(20)); | ||
await Cache.put('some-data', data, DateTime.now().addHours(2)) | ||
|
||
return data; | ||
``` | ||
|
||
If exists... return it, if it doesn't, add it then return it. | ||
|
||
Now lets look at the remember method: | ||
|
||
```typescript | ||
const data = await Cache.remember('some-data', () => 'some value', DateTime.now().addHours(2)); | ||
|
||
return data; // gives us "some-data" | ||
``` | ||
|
||
All of that original boilerplate/logic reduced down to 1 line :) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.