ladda-cache
Advanced tools
Comparing version 0.1.2 to 0.1.3
@@ -896,3 +896,3 @@ module.exports = | ||
var getTtl = function getTtl(e) { | ||
return (e.ttl || 0) * 1000; | ||
return (e.ttl || 300) * 1000; | ||
}; | ||
@@ -899,0 +899,0 @@ |
@@ -7,3 +7,3 @@ # Custom ID | ||
``` | ||
```javascript | ||
const config = { | ||
@@ -24,3 +24,3 @@ user: { | ||
``` | ||
```javascript | ||
getUser.operation = 'READ'; | ||
@@ -27,0 +27,0 @@ getUser.idFrom = user => user._id; |
@@ -7,3 +7,3 @@ # Invalidation | ||
``` | ||
```javascript | ||
const config = { | ||
@@ -23,3 +23,3 @@ topList: { | ||
``` | ||
```javascript | ||
const config = { | ||
@@ -43,3 +43,3 @@ topList: { | ||
``` | ||
```javascript | ||
recalculateTopPlayers.invalidates = ['getTopPlayers']; | ||
@@ -46,0 +46,0 @@ function recalculateTopPlayers() { |
@@ -8,3 +8,3 @@ # Views | ||
``` | ||
```javascript | ||
const config = { | ||
@@ -11,0 +11,0 @@ user: { |
@@ -5,4 +5,4 @@ # Background | ||
The issue we started to encounter was that loading all the data took quite a while, especially for large companies. First step was to ensure that we only loaded the data that is needed. However, even this was quite a lot of data. We started to explore different solutions, we invested quite a lot in evaluating GraphQL and Relay. However, we didn't find anything that made us really happy. We previously switched from Angular 1 to React and we wanted a solution that would make it easier, rather than harder, to jump single page application framework the next time. In addition to this, we didn't want our application code to get more complex, but if anything, we would like it to get less complex. We didn't feel that any existing solution fullfilled all our wishes. | ||
The issue we started to encounter was that loading all the data took quite a while, especially for large companies. First step was to ensure that we only loaded the data that is needed. However, even this was quite a lot of data. We started to explore different solutions, we invested quite a lot in evaluating GraphQL and Relay. But we didn't find anything that made us really happy. We previously switched from Angular 1 to React and we wanted a solution that would make it easier, rather than harder, to jump single page application framework the next time. In addition to this, we didn't want our application code to get more complex, but if anything, we would like it to get less complex. We didn't feel that any existing solution fullfilled all our wishes. | ||
We were a couple of developers at Small Improvements that got really intrerested in this topic, we started to look around for more solutions and experiment with our own solutions. Finally we met and discussed our findings. We picked Ladda for its simplicity, it living outside of the application code and it promoting something that we thought is a good idea in general: well-defined entities. We also realized that using something that is not aware of the framework would help us to synchronize data between React and Angular (we are still using both frameworks). Ladda doesn't care if the request comes from React or Angular, and the cache works regardless of where the request originated. Hence we could synchronize data between Angular and React without doing anything more than using Ladda. If we loaded all users in Angular, updated one of them, and then loaded all users in React, we would get the latest data in React without the need for an API-request. This is how Ladda was born. But enough history, let's get more concrete and look at what benefits you can get. |
@@ -17,3 +17,3 @@ # Operations | ||
``` | ||
```javascript | ||
createUser.operation = 'CREATE'; | ||
@@ -20,0 +20,0 @@ function createUser(user) { |
@@ -11,3 +11,3 @@ # Time To Live | ||
``` | ||
```javascript | ||
const config = { | ||
@@ -14,0 +14,0 @@ user: { |
@@ -15,3 +15,3 @@ # Contribute | ||
- Optimistic Updates | ||
- Optimistic updates | ||
@@ -18,0 +18,0 @@ - Framework integrations (for example a React HOC that rerenders on changes to entities) |
# Introduction | ||
Ladda is an independent, lightweight caching solution for your JavaScript application. It is a library simple to get started with yet supports sophisticated cache management. Let's start by looking at the background of Ladda and then look at how it can be useful for you and how to proceeed if you want to give Ladda a shot. | ||
Ladda is an independent, lightweight caching solution for your JavaScript application. It is a library simple to get started with yet supports sophisticated cache management. In this section we will to explain how it can be useful for you and how to proceeed if you want to give Ladda a shot. | ||
@@ -11,3 +11,3 @@ ## How Does It Help Me? | ||
``` | ||
```javascript | ||
var result; | ||
@@ -31,3 +31,3 @@ | ||
``` | ||
```javascript | ||
return apiService.getList(); | ||
@@ -38,3 +38,3 @@ ``` | ||
``` | ||
```javascript | ||
getList.operation = 'READ'; | ||
@@ -48,3 +48,3 @@ function getList() { | ||
[Ladda does support those operations](/docs/basics/Operations.md). When you update the list, by using a `CREATE`, `UPDATE` or `DELETE` operation, the requests are made to the API as usual. However, Ladda will also update your cache. Once you request the list of items again from the API, you will get the updated result from the cache without making a new API-request. For example, if you changed the name of a user, there's no need to refetch all users from you backend. Ladda ensures that you get up to date data if you would for example call "getAllUsers" again, without an API-request being made. | ||
[Ladda does support those operations](/docs/basics/Operations.md). When you update the list, by using a `CREATE`, `UPDATE` or `DELETE` operation, the requests are made to the API as usual. However, Ladda will also update your cache. Once you request the list of items again from the API, you will get the updated result from the cache without making a new API-request. For example, if you changed the name of a user, there's no need to refetch all users from your backend. Ladda ensures that you get up to date data if you would for example call "getAllUsers" again, without an API-request being made. | ||
@@ -51,0 +51,0 @@ ## When to Use Ladda |
@@ -9,4 +9,4 @@ # Main Contributors | ||
- [**Gernot Höflechner**](https://github.com/LFDM/): Pushed Peter to work on Ladda. Kept bringing it up until it happened. Also involved in the [initial discussions](./Introduction.md#background) and discussions about the future of Ladda. | ||
- [**Gernot Höflechner**](https://github.com/LFDM/): Pushed Peter to work on Ladda. Kept bringing it up until it happened. Also involved in the [initial discussions](./Background.md) and discussions about the future of Ladda. | ||
- [**Peter Crona**](https://github.com/petercrona): Started the project and have worked hard to keep it nice and tidy. Focusing on the code, but also tried writing some documentation. | ||
- [**Peter Crona**](https://github.com/petercrona): Started the project and has worked hard to keep it nice and tidy. Focusing on the code, but also tried writing some documentation. |
@@ -7,5 +7,5 @@ # Table of Contents | ||
* [Demos](/docs/Demos.md) | ||
* [Getting Started](/docs/GettingStarted.md) | ||
* [Concepts](/docs/Concepts.md) | ||
* [Basics](/docs/basics/README.md) | ||
* [Getting Started](/docs/GettingStarted.md) | ||
* [Operations](/docs/basics/Operations.md) | ||
@@ -12,0 +12,0 @@ * [Time To Live](/docs/basics/TimeToLive.md) |
# Polling | ||
Caching and polling are not natural friends. We still didn't find a very nice way to make it work, but we did find a way to make it work. In the future you might get (or create a PR!) something fancy like the possibility to specify a cache alias (making poll write into the cache of getAll). | ||
``` | ||
```javascript | ||
getAll.operation = 'READ'; | ||
@@ -6,0 +6,0 @@ export function getAll(query) { |
@@ -26,3 +26,3 @@ # Separate API Folder | ||
``` | ||
```javascript | ||
import * as userApi from './user'; | ||
@@ -46,3 +46,3 @@ import * as miniUserApi from './mini-user'; | ||
user.js: | ||
``` | ||
```javascript | ||
getUsers.operation = 'READ'; | ||
@@ -55,3 +55,3 @@ export function getUsers() { | ||
mini-user.js: | ||
``` | ||
```javascript | ||
getMiniUsers.operation = 'READ'; | ||
@@ -65,7 +65,7 @@ export function getMiniUsers() { | ||
``` | ||
```javascript | ||
import api from 'api'; | ||
api.miniUser.getMiniUsers().then(miniUsers => console.log(miniUsers); | ||
api.user.getUsers(users => console.log(users)); | ||
api.user.getUsers().then(users => console.log(users)); | ||
``` | ||
@@ -75,3 +75,3 @@ | ||
``` | ||
```javascript | ||
import * as user from './user'; | ||
@@ -78,0 +78,0 @@ import * as miniUser from './mini-user'; |
{ | ||
"name": "ladda-cache", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "Data fetching layer with support for caching", | ||
@@ -5,0 +5,0 @@ "main": "dist/bundle.js", |
@@ -8,3 +8,3 @@ # Ladda | ||
When developing your application you shouldn't care about Ladda nor caching. You should just assume that backend calls are for free, that they will be cached if possible and data will be refetched if it has to. This can **simplify you application code**. | ||
When developing your application you shouldn't care about Ladda nor caching. You should just assume that backend calls are for free, that they will be cached if possible and data will be refetched if it has to. This can **simplify your application code**. | ||
@@ -11,0 +11,0 @@ If you get bored of Ladda you can easily get rid of it. Ladda is designed to influence your application code as little as possible. We want you to get hooked, but not because of the cost of getting rid of Ladda. |
@@ -9,6 +9,6 @@ import {get as getFromEs, | ||
getValue} from 'query-cache'; | ||
import {passThrough, compose, prop} from 'fp'; | ||
import {passThrough, compose} from 'fp'; | ||
import {addId, removeId} from 'id-helper'; | ||
const getTtl = e => (e.ttl || 0) * 1000; | ||
const getTtl = e => (e.ttl || 300) * 1000; | ||
@@ -15,0 +15,0 @@ // Entity -> Int -> Bool |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
554892
137
3374
1
3