ri0t1985 / api-creator

Project that allows you to turn static website data into an API through CSS selectors
MIT License
6 stars 0 forks source link

Implement caching #5

Open ri0t1985 opened 7 years ago

ri0t1985 commented 7 years ago

Currently, the HTML is retrieved "on demand" when calling a user created route. This is bad for several reasons:

To fix this, we should implement 2 different caches:

Source retrieval caching The HTML source should be cached, and checked if the html source has changed since the last request

` $headers = get_headers( $remotePath , 1 ); $remote_mod_date = strtotime( $headers['Last-Modified'] ); $local_mod_date = filemtime( $localPath );

if ( $local_mod_date >= $remote_mod_date ) {
    // Local version up to date 
} else {
    // retrieve new source

} ` Where to cache the source should be configurable.

Caching parsed data The actual parsed data should be cacheable as well, with a TTL configurable by the user. If the parsed data is in the cache, and still valid, theres no need to retrieve the HTML source as well, so we can just serve the data from the cache.

Prewarming the cache Optionally we should have a script that can prewarm the cache. Its up to the host of the project if he wants to run this script (in a cronjob for instance).

ri0t1985 commented 7 years ago

Partial implementation of the cache is present in pull request #13

ri0t1985 commented 7 years ago

Caching of the retrieval of HTML is implemented in 0.3.

caching of the JSON response is to be implemented for 0.4