# API cache

**URL:** <https://community.glideapps.com/t/api-cache/29869>\
**Category:** Ask for Help\
**Tags:** custom-code\
**Created:** [August 2, 2021, 2:16am UTC](https://community.glideapps.com/t/api-cache/29869 "2021-08-02T02:16:41Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Manu.n](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/manu.n/32/11679_2.png) [@Manu.n](https://community.glideapps.com/u/Manu.n)\
**Post date:** [August 2, 2021, 2:16am UTC](https://community.glideapps.com/t/api-cache/29869/1 "2021-08-02T02:16:41Z")

</div>

Hello,  
I noticed that there are API calls if:

- You change Tab
- You add a column in the Data Editor
- If you view in an inline-list
- If you switch from Layout to Data Editor
- Also be careful, if you use a Text-Entry component directly to do a search, the APIs are called for each character entered. (I recommend using a button to validate the search)

Here is an attempt to cache API calls.

To limit the number of calls to an API, here is some code with caching.  
(There may be another method !!)

 ![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/2/3/239a5b029d99b4fdbb8d70de9f17be1e4defb3e8.png)

---

<div class="post-metadata">

**Author:** ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)\
**Post date:** [August 2, 2021, 2:18am UTC](https://community.glideapps.com/t/api-cache/29869/2 "2021-08-02T02:18:57Z")

</div>

This is an issue I want to solve too in order to use paid APIs more efficiently. Did this work nicely for you?

---

<div class="post-metadata">

**Author:** ![Manu.n](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/manu.n/32/11679_2.png) [@Manu.n](https://community.glideapps.com/u/Manu.n)\
**Post date:** [August 2, 2021, 2:21am UTC](https://community.glideapps.com/t/api-cache/29869/3 "2021-08-02T02:21:25Z")

</div>

Yes, it does limit calls a lot.  
There is still an issue when you open an application, you still have to do some tests.

---

<div class="post-metadata">

**Author:** ![Uzo](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/uzo/32/22639_2.png) [@Uzo](https://community.glideapps.com/u/Uzo)\
**Post date:** [August 2, 2021, 2:23am UTC](https://community.glideapps.com/t/api-cache/29869/4 "2021-08-02T02:23:49Z")

</div>

yep … thats why i made restriction to return from function if parameter is empty… later i add if is bigger than 3 characters that dont contain digits thats cut off api calls by 80%

---

<div class="post-metadata">

**Author:** ![Manu.n](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/manu.n/32/11679_2.png) [@Manu.n](https://community.glideapps.com/u/Manu.n)\
**Post date:** [August 2, 2021, 2:31am UTC](https://community.glideapps.com/t/api-cache/29869/5 "2021-08-02T02:31:12Z")

</div>

Version 2  
I added a small error handling in case of problem with google map or a problem with the API key

 ![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/2/3/239a5b029d99b4fdbb8d70de9f17be1e4defb3e8.png)

---

<div class="post-metadata">

**Author:** ![Manu.n](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/manu.n/32/11679_2.png) [@Manu.n](https://community.glideapps.com/u/Manu.n)\
**Post date:** [August 2, 2021, 2:41am UTC](https://community.glideapps.com/t/api-cache/29869/6 "2021-08-02T02:41:34Z")

</div>

The problem is if you use an array, for example, addresses and you add a YC column with the API calls, if you have 100 rows, I think and I’m pretty sure when opening the app (and even with this cache) it will have 100 API calls for refresh.  
So for paying, it must be limited to a particular search

---

<div class="post-metadata">

**Author:** ![Uzo](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/uzo/32/22639_2.png) [@Uzo](https://community.glideapps.com/u/Uzo)\
**Post date:** [August 2, 2021, 2:42am UTC](https://community.glideapps.com/t/api-cache/29869/7 "2021-08-02T02:42:59Z")

</div>

add also restriction for stupid addresses like someone put just digits or address is way to short like less that 3 alpha characters

---

<div class="post-metadata">

**Author:** ![Uzo](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/uzo/32/22639_2.png) [@Uzo](https://community.glideapps.com/u/Uzo)\
**Post date:** [August 2, 2021, 2:44am UTC](https://community.glideapps.com/t/api-cache/29869/8 "2021-08-02T02:44:46Z")

</div>

thats why i went back to triggered google script it only calling for a changed single cell … also your API key is exposed in App

---

<div class="post-metadata">

**Author:** ![Manu.n](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/manu.n/32/11679_2.png) [@Manu.n](https://community.glideapps.com/u/Manu.n)\
**Post date:** [August 2, 2021, 2:48am UTC](https://community.glideapps.com/t/api-cache/29869/9 "2021-08-02T02:48:18Z")

</div>

> [@Uzo](#):
>
> ajouter également une restriction pour les adresses stupides comme quelqu’un qui met juste des chiffres ou l’adresse est trop courte comme moins de 3 caractères alphabétiques

no I do not limit to the number of characters because there are city names \<4 characters, same for the numbers, sometimes we specify the postal code

---

<div class="post-metadata">

**Author:** ![Uzo](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/uzo/32/22639_2.png) [@Uzo](https://community.glideapps.com/u/Uzo)\
**Post date:** [August 2, 2021, 2:49am UTC](https://community.glideapps.com/t/api-cache/29869/10 "2021-08-02T02:49:22Z")

</div>

thats why i said less than 3 😉 … but anyway, you will for sure get wrong address if you put even 4 characters… so no sense to call with that

---

<div class="post-metadata">

**Author:** ![Manu.n](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/manu.n/32/11679_2.png) [@Manu.n](https://community.glideapps.com/u/Manu.n)\
**Post date:** [August 2, 2021, 2:50am UTC](https://community.glideapps.com/t/api-cache/29869/11 "2021-08-02T02:50:08Z")

</div>

> [@Uzo](#):
>
> thats why i went back to triggered google script it only calling for a changed single cell … also your API key is exposed in App

everything on computer media is hackable.  
for APIs like those of google, there is still the possibility to restrict to https

---

<div class="post-metadata">

**Author:** ![Manu.n](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/manu.n/32/11679_2.png) [@Manu.n](https://community.glideapps.com/u/Manu.n)\
**Post date:** [August 2, 2021, 2:51am UTC](https://community.glideapps.com/t/api-cache/29869/12 "2021-08-02T02:51:30Z")

</div>

> [@Uzo](#):
>
> thats why i said less than 3 😉 … but anyway, you will for sure get wrong address if you put even 4 characters… so no sense to call with that

No in France there are cities like

- Y
- By
- Eu

---

<div class="post-metadata">

**Author:** ![Uzo](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/uzo/32/22639_2.png) [@Uzo](https://community.glideapps.com/u/Uzo)\
**Post date:** [August 2, 2021, 2:54am UTC](https://community.glideapps.com/t/api-cache/29869/13 "2021-08-02T02:54:38Z")

</div>

this is the result of putting just Y

![Screen Shot 2021-08-01 at 10.54.02 PM](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/5/f/5f8e939f04e473896e850b6e447364f891c5999c.png)

so you just waisted one call

---

<div class="post-metadata">

**Author:** ![Uzo](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/uzo/32/22639_2.png) [@Uzo](https://community.glideapps.com/u/Uzo)\
**Post date:** [August 2, 2021, 2:59am UTC](https://community.glideapps.com/t/api-cache/29869/14 "2021-08-02T02:59:05Z")

</div>

I know everything is hackable… but good luck finding my API key in Glide App, when it comes from google script

---

<div class="post-metadata">

**Author:** ![Manu.n](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/manu.n/32/11679_2.png) [@Manu.n](https://community.glideapps.com/u/Manu.n)\
**Post date:** [August 2, 2021, 3:02am UTC](https://community.glideapps.com/t/api-cache/29869/15 "2021-08-02T03:02:56Z")

</div>

> [@Uzo](#):
>
> this is the result of putting just Y

For my personal case, I filtered through France, so he easily finds “Y”

---

<div class="post-metadata">

**Author:** ![Uzo](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/uzo/32/22639_2.png) [@Uzo](https://community.glideapps.com/u/Uzo)\
**Post date:** [August 2, 2021, 3:04am UTC](https://community.glideapps.com/t/api-cache/29869/16 "2021-08-02T03:04:12Z")

</div>

hmmm… but is a correct full address that you are looking for? 😉  
my point is… you can eliminate few unnecessary calls if you limit entry output… in a scale of a month with many users… that might save you good money… for a personal use. you prabably never gonna cross free limit… so no need for restrictions at-all

---

<div class="post-metadata">

**Author:** ![Manu.n](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/manu.n/32/11679_2.png) [@Manu.n](https://community.glideapps.com/u/Manu.n)\
**Post date:** [August 2, 2021, 3:41am UTC](https://community.glideapps.com/t/api-cache/29869/17 "2021-08-02T03:41:44Z")

</div>

Just for Laughs,  
I coded my Key Api in …

 ![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/5/4/54d86f2e889e7e5f416ae9b1f3ffafcc4a28b606.png)

---

<div class="post-metadata">

**Author:** ![Uzo](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/uzo/32/22639_2.png) [@Uzo](https://community.glideapps.com/u/Uzo)\
**Post date:** [August 2, 2021, 4:07am UTC](https://community.glideapps.com/t/api-cache/29869/18 "2021-08-02T04:07:42Z")

</div>

i don’t think that’s funny… i think this is smart… 😉

---

<div class="post-metadata">

**Author:** ![Manu.n](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/manu.n/32/11679_2.png) [@Manu.n](https://community.glideapps.com/u/Manu.n)\
**Post date:** [August 2, 2021, 4:09am UTC](https://community.glideapps.com/t/api-cache/29869/19 "2021-08-02T04:09:10Z")

</div>

Well yes it’s funny  
Because if someone is able to find the parameters from an application, it is necessarily reading a script

---

<div class="post-metadata">

**Author:** ![Uzo](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/uzo/32/22639_2.png) [@Uzo](https://community.glideapps.com/u/Uzo)\
**Post date:** [August 2, 2021, 4:11am UTC](https://community.glideapps.com/t/api-cache/29869/20 "2021-08-02T04:11:52Z")

</div>

hmm… yep but it is another obstacle to cross…
