<commit_before># Ladda
Ladda is a library that helps you with caching, invalidation of caches and to handle different representations of the same data in a performant and memory efficient way. The main goal with Ladda is to make it easy for you to add sophisticated caching without making your application code more complex. Ladda will take care of logic that would otherwise increase the complexity of your application code, and it will do so in a corner outside of your application. You can expect a significant performance boost (if you didn't have any caching already) with possibly no changes to you application code. Ladda is designed to be something you can ignore. 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. 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.

# When to Use Ladda
Ladda is not meant to cover all possible use cases. You should use Ladda when you have clear entities. The entities need to be well-defined, for example, you might have a User entity, which contains an id, name, email and contact details. Then you might have a ListUser which only contains an id and a name. The important bit is that these concepts exist and that you refer to them as User and ListUser rather than "A user might have an id, name, email and contact details, but sometimes only id and name". Of course, if you come up with creative ways of using Ladda, and they provide you with a benefit, go ahead!  

# Get Started
Do a `npm install ladda-cache` in your project. Now, to use Ladda you need to configure it and export an API built from the configuration. You might create a file "api/index.js":

```javascript
import * as project from './project';
import { build } from 'ladda-cache';

const config = {
    projects: {
        ttl: 300,
        api: project
    }
};

export default build(config);
```

where project is a bunch of api-methods returning promises, eg:

```javascript
createProject.operation = 'CREATE';
export function createProject(project) {
    return post(resource, { postData: project }); // Must return a project (with ID).
}

getProjects.operation = 'READ';
export function getProjects() {
    return get(resource);
}
```

# Concepts
* ID: Unique identifier for a EntitiyValue. By default assumed to be the property "id" of an object. But can be overriden (see Ladda Config).

* EntityValue: An object with an ID

* BlobValue: Does not require an ID. Can be either a list, an object or just a single value. Suitable when you just want to cache an API call.


## Operations
* CREATE: An API call which returns an EntitiyValue.

* READ: An API call which returns an EntityValue, or a list of EntityValues.

* UPDATE: Takes the updated EntitiyValue as the first argument. No assumptions on what is returned by the server are made.

* DELETE: Takes an ID as the first argument. Server must return 200, or the delete will be reverted. No assumptions on what is returned by the server are made.<commit_msg>Only reference the get started in the introduction.<commit_after># Ladda
Ladda is a library that helps you with caching, invalidation of caches and to handle different representations of the same data in a performant and memory efficient way. The main goal with Ladda is to make it easy for you to add sophisticated caching without making your application code more complex. Ladda will take care of logic that would otherwise increase the complexity of your application code, and it will do so in a corner outside of your application. You can expect a significant performance boost (if you didn't have any caching already) with possibly no changes to you application code. Ladda is designed to be something you can ignore. 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. 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.

# When to Use Ladda
Ladda is not meant to cover all possible use cases. You should use Ladda when you have clear entities. The entities need to be well-defined, for example, you might have a User entity, which contains an id, name, email and contact details. Then you might have a ListUser which only contains an id and a name. The important bit is that these concepts exist and that you refer to them as User and ListUser rather than "A user might have an id, name, email and contact details, but sometimes only id and name". Of course, if you come up with creative ways of using Ladda, and they provide you with a benefit, go ahead!  

# Get Started
Check out the [guide](/docs/GettingStarted.md) for getting started. And have a look in the [examples folder](https://github.com/petercrona/ladda/tree/master/examples). 

# Concepts
* ID: Unique identifier for a EntitiyValue. By default assumed to be the property "id" of an object. But can be overriden (see Ladda Config).

* EntityValue: An object with an ID

* BlobValue: Does not require an ID. Can be either a list, an object or just a single value. Suitable when you just want to cache an API call.


## Operations
* CREATE: An API call which returns an EntitiyValue.

* READ: An API call which returns an EntityValue, or a list of EntityValues.

* UPDATE: Takes the updated EntitiyValue as the first argument. No assumptions on what is returned by the server are made.

* DELETE: Takes an ID as the first argument. Server must return 200, or the delete will be reverted. No assumptions on what is returned by the server are made.
{'fraction_non_alphanumeric': 0.04491567874436467, 'fraction_numerical': 0.001502755050926699, 'mean_word_length': 4.089209855564996, 'pattern_counts': {'":': 1, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4364186', 'n_tokens_mistral': 1521, 'n_tokens_neox': 1447, 'n_words': 987}