Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/jokinkuang/pagecache.js

a cache that only live in a page, just like cookie cache but it is page cache
https://github.com/jokinkuang/pagecache.js

Last synced: 5 days ago
JSON representation

a cache that only live in a page, just like cookie cache but it is page cache

Awesome Lists containing this project

README

        

# pagecache.js
a cache that only live in a page, just like cookie cache but it is page cache

## Dependence
no dependece

## Why Need It
sometimes we got an API that returns like this:

`
{
comments: "1",
likes: "2",
reposts: "3"
}
`

usually we do this by one request:
```javascript

jQuery.getJson("the API url", function(json){
// handle the comments
// handle the likes
// handle the reposts
});

```

but with pagecache we can do following by one reqeust too:
```javascript

$PC("the API url", function(json){
// handle the comments
});
$PC("the API url", function(json){
// handle the likes
});
$PC("the API url", function(json){
// handle the reposts
});

```
they are separate and independent

## Usage

### json
``` javascript
$PC("http://jokinkuang.github.io/Postfile", function(json, state, xmlhttp_obj){
// handle the json object
}, function(state, xmlhttp_obj) {
// handle the error
});
```

### jsonp
``` javascript
$PC("http://jokinkuang.github.io/Postfile?callback=?", function(json, state, jsonp_obj){
// handle the json object
}, function(state, jsonp_obj){
// handle the error
});
```
> just add a `callback=?` into the request URL

### open the log
set `$PC.Log.level=2` before function call
> DEBUG: 2
> INFO: 1
> ERROR: 0

### $PC function
$PC("url", successFunctionCall, errorFunctionCall);

`json`
successFunctionCall(json, state, xmlhttp_obj);
errorFunctionCall(state, xmlhttp_obj);

`jsonp`
successFunctionCall(json, state, jsonp_obj);
errorFunctionCall(state, jsonp_obj);

### `NOTE` have not support POST

## License
Under The [MIT](https://tldrlegal.com/license/mit-license) License