Expand Your HTML Page File Cache with Cloud Storage

简介: Most people use cloud storage apps, such as Object Storage Service (OSS), for images or other large files.

ST_003

Background

Most people use cloud storage apps, such as Object Storage Service (OSS), for images or other large files. However, cloud storage is not intrinsically limited to a single use case but merely provides a platform for us to solve a wide range of problems. In this article, we will explain how to use Alibaba Cloud OSS to solve the problem of insufficient HTML cache space.

Caching is crucial for websites and can solve most complex performance issues. There are many types of cache, the most common ones being the memory cache and the disk cache (page cache). Memory cache is quicker and is typically used to store critical and hot content, but it cannot be used to store large amounts of data. Disk cache on the other hand is much slower because it employs disk I/O. However, the disk cache can be used for performing complex database queries, processing business logic, and accelerating page loading.

Scenario

In this example, several hundred GBs of HTML page file cache data is generated every day. What will happen if we put all of these files directly onto a hard drive?

  1. The hard drive space will be insufficient. Although drive space is relatively cheap, it is difficult to predict how much space your app will require as your business grows. You could potentially store these files on several drives, but that will make management more difficult.
  2. The HTML file cache may expire, at which point it needs to be removed to free up drive space. The deletion of several hundred GBs of small files, however, will create high I/O loads, seriously affecting web services.

Solution

We can use OSS to store these small HTML page files. The advantages of using OSS are:

  1. You do not need to worry about affecting the host web services when removing expired files. Scripts are run regularly every day to delete expired files on the OSS and to release space.
  2. OSS and ECS are interconnected over the intranet without any Internet traffic involved, significantly reducing network latency. Despite the network traffic, response time will be limited to within 100 ms.
  3. The OSS response header can be used as an effective means of cache control.

Uploading and Removing Files on OSS

Step 1: Activate OSS

Before using Alibaba Cloud OSS service, ensure that you have registered for an Alibaba Cloud account and completed real-name authentication. If you do not have an Alibaba Cloud account yet, the system will prompt you to register for an account when you activate OSS.

Process

  1. Log on to the Alibaba Cloud official website.
  2. Go to the OSS Product Detail Page and click Activate Now.
  3. After OSS service is activated, click Console to access the OSS console interface.
    You can also click Console in the upper-right menu bar on the homepage to access the Alibaba Cloud console, and click on the button shown in the figure below to access the OSS console interface.

Step 2: Create a bucket

After you activate Alibaba Cloud OSS service, you need to use the OSS console to create a bucket for storing files.

Process

  1. Go to the OSS console interface.
  2. Click Manage Buckets > New Bucket to open the New Bucket dialog box.
  3. In the Bucket Name field, enter the name of your bucket. The bucket name must comply with the naming rules and must be unique among all existing bucket names in Alibaba Cloud OSS. The bucket name may not be changed after being created. For more information about bucket naming, refer to OSS Basic Concepts.
  4. In the Region drop-down box, select the data center of the bucket. The region may not be changed after being subscribed. To access the OSS through the ECS Intranet, you can select the same region as your ECS for the bucket. For more information about regions, refer to Regions and Endpoints in the Alibaba Cloud OSS Developer Guide.
  5. In the ACL drop-down box, select an access permission for the bucket.
    Public Read/Write: Any users (including anonymous users) can perform read, write, and delete operations on the objects in the bucket. The fees incurred by these operations will be borne by the creator of the bucket. Use this permission with caution.

Public Read: Only the creator of the bucket can perform write and delete operations on the objects in the bucket. Any users (including anonymous users) can read the objects in the bucket.
Private: Only the creator of the bucket can perform read, write, and delete operations on the objects in the bucket. Other users cannot access the objects in the bucket without authorization.

  1. Click Submit. The bucket is successfully created.

Step 3: Upload a file

After you create a bucket, you can upload all types of files to the bucket. Using the OSS console, you can upload files smaller than 5 GB. For details about how to upload files larger than 5 GB, refer to Multipart Upload in the Alibaba Cloud OSS Developer Guide.

Process

  1. Go to the OSS console interface.
  2. Click on the name of your desired bucket to open the bucket management page.
  3. Click Manage Objects to open the object management page of the bucket.
  4. Click Upload File to open the file selection dialog box.
  5. Select the file you want to upload and click Open. After the file has been uploaded successfully, click Refresh to view the uploaded file.

Step 4: Delete an object

If you do not need to store an uploaded object any longer, you can delete it to avoid further charges. You can delete a single object or delete multiple objects in batches in the OSS console.

Process

  1. Go to the OSS console interface.
  2. Click on the name of the bucket that contains the object to be deleted to open the bucket management page.
  3. Click Manage Objects to open the object management page.
  4. Click the Delete link of the target object.
  5. Click OK to delete the object. To delete objects in batches, select the objects to be deleted and click Batch Delete. You can delete up to 50 objects at a time in the OSS console. For more flexible selection methods, refer Delete and Object in the Alibaba Cloud OSS Developer Guide.

Summary

In this article, we introduced the problems with conventional caching methods and discussed the method of using OSS to cache HTML files. With OSS, you do not have to worry about disk space limitations or high server loads from deleting multiple expired files. At less than five Chinese yuan a day, OSS is a cost effective solution to all your file storage needs. Try it today!

目录
相关文章
|
移动开发 前端开发 Android开发
前端html input =“file“ ios/安卓解决无法选择图库/拍照问题
前端html input =“file“ ios/安卓解决无法选择图库/拍照问题
1621 0
|
XML JSON 移动开发
HTML5 input file,accept
accept表示可以上传文件类型,image表示图片,*表示所有支持的格式。在上传文件的时候,需要限制指定的文件类型。
93 0
|
前端开发
HTML之图像数据base64、object file之间的相互转换
HTML之图像数据base64、object file之间的相互转换
|
前端开发 JavaScript
【前端】【探究】HTML - input类型为file时如何实现自定义文本以更好的美化
【前端】【探究】HTML - input类型为file时如何实现自定义文本以更好的美化
129 0
【前端】【探究】HTML - input类型为file时如何实现自定义文本以更好的美化
|
前端开发 CDN
html2canvas图片生成file格式传送到后台服务器
html2canvas图片生成file格式传送到后台服务器
|
Web App开发 前端开发 JavaScript
Chrome浏览器HTML支持本地(file协议)的AJAX请求
Chrome浏览器HTML支持本地(file协议)的AJAX请求
618 0
Chrome浏览器HTML支持本地(file协议)的AJAX请求
|
移动开发 JavaScript 前端开发
resumable.js —— 基于 HTML 5 File API 的文件上传组件 支持续传
resumable.js是一个 JavaScript 库,通过 HTML5 文件 API 提供了稳定和可恢复的批量上传功能。在上传大文件的时候将文件分割成小块,每块在上传失败的时候,上传会不断重试直到程序完成。这允许上传到本地或服务器的网络连接丢失后能够自动恢复上传。由于采用了分块技术,它也允许用户暂停和恢复上传。
924 0
resumable.js —— 基于 HTML 5 File API 的文件上传组件 支持续传
|
移动开发 JavaScript 前端开发
HTML5的 input:file上传类型控制
原文:HTML5的 input:file上传类型控制 HTML5的 input:file上传类型控制 2014年8月29日 90820次浏览 一、input:file属性 属性值有以下几个比较常用: accept:表示可以选择的文件MIME类型,多个MIME类型用英文逗号分开,常用的MIME类型见下表。
1524 0