Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2020-03-21 17:03:07

trenc
Plugin Author
From: ⛵️, currently Göteborg, SE
Registered: 2008-02-27
Posts: 574
Website GitHub

yab_api_cache - Simple url cache

Hi,

long time no see. I hope you are all doing fine in these times.

I’ve written a simple url cache for Textpattern CMS. I use it for caching API content or shared static HTML from one source. It’s relativly straightforward. It’s quite old, but now I was able to document it and write some help and finally publish it. I hope it’s useful for somebody.

It similar to etc_cache but for URLs

You can grab it from GitHub. The compiled plugin version is located under the /dist folder.

yab_api_cache

Simple URL cache.
Caches the outout of an url (simple GET APIs, URIs, websites etc.).
It can also be used to cache dynamic pages of the own website. Especially the ones with a lot of huge dynamic lists (but you can also use etc_cache parts of the site).

Version: 0.1.2

Table of contents

  1. Plugin requirements
  2. Configuration
  3. Tags
  4. Examples
  5. Changelog
  6. License
  7. Author contact

Plugin requirements

  • Textpattern >= 4.7.x

Configuration

Open the plugin code. The yab_api_cache function contains the configuration values. Can also be configured by tag attributes. See tag attribute for info.

Tags

yab_api_cache

This tag will output the content of a given url live or cached.

id: any valid string or empty
Default: not set
A valid string to identify the content, If not provided ist will be generated by md5 the utl attrbiute.

url: a valid string (URI)
Default: null
The URI which to be requested and shown

cached: integer|bool (1|0)
Default: true
If set to 0 (false) the requested content is live instead of the cached one.

cache_time: integer (seconds)
Default: 3600
Cache time in seconds

clear_cache: integer|bool (1|0)
Default: false
If set to 1 (truly) it will clear the entire cache.

Examples

Example: simplest

<txp:yab_api_cache url="https://exmaple.com/api/show/users" />

Shows the cached output of the given url. Renews the chache after 1 hour (3600 seconds). The md5 hash of the url is used as id.

Example: advanced

<txp:yab_api_cache id="my-api-call" url="https://exmaple.com/api/show/users" cache_time="86400" />

Shows the cached output of the given url. Renews the chache after 1 day (86400 seconds). An own id is privided

Example: no-cache

<txp:yab_api_cache id="my-api-call" url="https://exmaple.com/api/show/users" cached="0" />

Shows the live output of the given url. An own id is privided.

Example: reset

<txp:yab_api_cache clear_cache="1" />

Clears the entire cache (Empties the table).

Changelog

  • v0.1.2 – 2020-03-21
    • modified: add plugin help, public release
  • v0.1.1 – 2018-02-14
    • bugfix: id and url will be parsed
    • modifed: id not mandatory, will be created by url
  • v0.1.0 – 2017-10-29
    • initial release

Licence

This plugin is released under the GNU General Public License Version 2 and above

Author contact


Digital nomad, sailing the world on a sailboat: 32fthome.com

Offline

#2 2020-03-21 20:10:03

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,090
Website GitHub Mastodon Twitter

Re: yab_api_cache - Simple url cache

Just to say that the plugin looks cool and I will be taking it for a spin at some point.


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#3 2020-03-22 16:48:30

Pat64
Plugin Author
From: France
Registered: 2005-12-12
Posts: 1,634
GitHub Twitter

Re: yab_api_cache - Simple url cache

Hi Tommy.

Do you think your plugin can help me to catch and retrieve the JSON response from the Instagram API?

Last edited by Pat64 (2020-03-22 16:49:25)


Patrick.

Github | CodePen | Codier | Simplr theme | Wait Me: a maintenance theme | [\a mi.ni.ma]: a “Low Tech” simple Blog theme.

Offline

#4 2020-03-23 09:56:35

trenc
Plugin Author
From: ⛵️, currently Göteborg, SE
Registered: 2008-02-27
Posts: 574
Website GitHub

Re: yab_api_cache - Simple url cache

Hi Patrick,

the plugin currently only supports simply GET request (provided by the url attribute). Other HTTP methods (POST, PUT, DELETE) are not supported.
I’ve quickly checked the Instagram API and probably you need at least one POST request to retrieve the access token. So the plugin is probably not helping.
And, if I see this correctly, you need a JSON parser. But with this maybe I can help you, I written a small »JSON value retriever« as plugin (but very rough and undocumented).


Digital nomad, sailing the world on a sailboat: 32fthome.com

Offline

Board footer

Powered by FluxBB