1. 程式人生 > 其它 >清楚快取_使用github進行資料快取

清楚快取_使用github進行資料快取

Most people are aware of using GitHub as an easy tool to collaborate on coding projects, but few even realize that you can use it as a data storage and caching system — for free.

大多數人都知道使用GitHub作為在編碼專案上進行協作的簡便工具,但是很少有人意識到您可以免費將它用作資料儲存和快取系統。

Depending on your use case, this can be a really nice workflow and allow some nice tricks like using static sites with dynamically generated and cached content.

根據您的用例,這可能是一個非常不錯的工作流程,並允許使用一些不錯的技巧,例如使用具有動態生成和快取內容的靜態網站。

使用原始程式碼URL將GitHub託管的檔案作為資料來源進行引用 (Reference GitHub-Hosted Files as Data Sources Using Raw Code URLs)

The main idea that stands behind this is quite simple: GitHub offers a raw view for files that can be accessed via a URL and gives you the raw file without any of the “GitHub stuff” around it. So instead of seeing your text or JSON file with all the version history and the GUI to make changes or download, you just get the file itself hosted under that URL.

背後的主要思想很簡單:GitHub提供了可通過URL訪問的檔案的原始檢視,併為您提供了沒有任何“ GitHub內容”的原始檔案。 因此,您無需檢視具有所有版本歷史記錄和GUI進行更改或下載的文字或JSON檔案,而只需將檔案本身託管在該URL下即可。

The URL looks something like this:

URL看起來像這樣:

https://raw.githubusercontent.com/username/repositoryname/master/filename?token=dsaöjlksdajöldfasjöfa

This URL does not change between builds or commits, which means that you can use it as persistent storage. This is already pretty nifty and can save you from setting up a database on some projects. However, this can be used even better to do caching of all kinds of common requests.

該URL在生成或提交之間不會更改,這意味著您可以將其用作永續性儲存。 這已經很漂亮了,可以避免您在某些專案上建立資料庫。 但是,這甚至可以更好地用於快取各種常見請求。

使用自動任務快取結果 (Caching Results With an Automated Task)

In essence, you will need a way to automatically commit changes to the repository every so often. This can be stupidly simple with a batch script running on your own machine or a server. Something like this:

本質上,您將需要一種經常自動將更改提交到儲存庫的方法。 使用在自己的計算機或伺服器上執行的批處理指令碼,這可能非常簡單。 像這樣: