WO2023272919A1 - 一种资源数据读取方法、装置、电子设备和存储介质 - Google Patents

一种资源数据读取方法、装置、电子设备和存储介质 Download PDF

Info

Publication number
WO2023272919A1
WO2023272919A1 PCT/CN2021/115427 CN2021115427W WO2023272919A1 WO 2023272919 A1 WO2023272919 A1 WO 2023272919A1 CN 2021115427 W CN2021115427 W CN 2021115427W WO 2023272919 A1 WO2023272919 A1 WO 2023272919A1
Authority
WO
WIPO (PCT)
Prior art keywords
cache
resource
file
space
list
Prior art date
Application number
PCT/CN2021/115427
Other languages
English (en)
French (fr)
Inventor
王浩
林顺
Original Assignee
厦门雅基软件有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 厦门雅基软件有限公司 filed Critical 厦门雅基软件有限公司
Publication of WO2023272919A1 publication Critical patent/WO2023272919A1/zh

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/10File systems; File servers
    • G06F16/17Details of further file system functions
    • G06F16/172Caching, prefetching or hoarding of files
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/10File systems; File servers
    • G06F16/18File system types
    • G06F16/182Distributed file systems
    • G06F16/184Distributed file systems implemented as replicated file system
    • G06F16/1844Management specifically adapted to replicated file systems

Definitions

  • Embodiments of the present disclosure relate to the technical field of data processing, and in particular to a resource data reading method, device, electronic equipment, and storage medium.
  • the embodiment of the present disclosure provides a method for reading resource data.
  • a cache list file is created in the cache space in advance.
  • the cache list file stores the cache list.
  • the cache list includes the identification field of the cache file, and the cache file is cached in Files in the cache space, methods include:
  • the local space After determining that the path is a remote path, determine whether the file corresponding to the resource is stored in the local space, the local space includes the cache space and the temporary file directory;
  • an embodiment of the present disclosure provides a method for loading resource data, including:
  • the embodiment of the present disclosure provides a device for reading resource data.
  • a cache list file is created in the cache space in advance.
  • the cache list file stores the cache list.
  • the cache list includes the identification field of the cache file.
  • the cache file is cached in Files in the cache space, methods include:
  • the acquisition module is used to acquire the path of the resource to be read, wherein the path is obtained by parsing the tag value corresponding to the resource;
  • the judging module is used to judge whether the file corresponding to the resource is stored in the local space after determining that the path is a remote path, and the local space includes a cache space and a temporary file directory;
  • the download module is used to download the file corresponding to the resource to the temporary file directory according to the remote path if the file corresponding to the resource is not stored in the local space;
  • the reading module is used to read the files corresponding to the resources in the temporary file directory into the memory.
  • an embodiment of the present disclosure provides a device for loading resource data, including:
  • the first obtaining module is used to obtain the tag value of the resource to be processed
  • the first reading module is used to read the file corresponding to the resource into the memory by using the above-mentioned resource data reading device according to the tag value;
  • the dependent module is used to obtain a list of dependent resources according to the files corresponding to the resources;
  • the loading module is used to load and initialize the dependent resources in the dependent resource list to obtain the loaded resource data.
  • an electronic device including:
  • the memory is used to store a computer program that can run on the processor, and when the processor executes the computer program, the above resource data reading method is realized.
  • an electronic device including:
  • the memory is used to store a computer program that can run on the processor, and when the processor executes the computer program, the above resource data loading method is implemented.
  • the embodiments of the present disclosure provide a computer-readable storage medium, on which a computer program is stored.
  • the computer program is executed by a processor, the steps of the resource data reading method described above are implemented, or the resource data described above is used to Data loading method.
  • FIG. 1 is a schematic diagram of a resource storage form provided by an embodiment of the present disclosure
  • FIG. 2 is a schematic diagram of an application scenario provided by an embodiment of the present disclosure
  • FIG. 3 is a schematic flowchart of a resource data loading method provided by an embodiment of the present disclosure
  • FIG. 4 is a schematic flowchart of a method for reading resource data provided by an embodiment of the present disclosure
  • FIG. 5 is a schematic flowchart of a resource data loading method provided by an embodiment of the present disclosure.
  • FIG. 6 is a schematic flowchart of a method for reading resource data provided by an embodiment of the present disclosure
  • FIG. 7 is a schematic flowchart of a method for reading resource data provided by an embodiment of the present disclosure.
  • FIG. 8 is a schematic flowchart of a method for reading resource data provided by an embodiment of the present disclosure.
  • FIG. 9 is a schematic structural diagram of a device for loading resource data provided by an embodiment of the present disclosure.
  • FIG. 10 is a schematic structural diagram of a device for reading resource data provided by an embodiment of the present disclosure.
  • Fig. 11 is a schematic structural diagram of an electronic device provided by an embodiment of the present disclosure.
  • a cache list file is created in the cache space in advance, the cache list file stores the cache list, and the cache list stores the identification field of the cache file, and the cache file is stored in the cache space
  • For cached files obtain the path of the resource to be read. After determining that the path is a remote path, further determine whether the file corresponding to the resource is stored in the local space. If not, download the file to the temporary through the remote path file directory, and read the file from the temporary file directory into memory.
  • the path of the resource is a remote path
  • a game is composed of various resources.
  • Resources can be understood as a combination of data, which is the basic component of the game and controls the realization of the game.
  • resources can specifically refer to game scenes, models, audio, video, text, and textures.
  • all the various resources used will be exported to the system file in the form of files, and the resources will be named with unique identifiers (names) in the world, for example, in Figure 1
  • the naming expressions of various resources are shown as an example. All kinds of resources exist in the form of files and have unique corresponding file names.
  • the files corresponding to each resource included in the system file in Figure 1 can be divided into road, tree, and car. And sub-files included in each file, road01, car101, etc.
  • the above-mentioned game resources can be loaded on the mini-game platform.
  • the characteristics of the mini-game platform in terms of resource management include: package size restriction, mini-game platform to reduce the game loading time, speed up the game startup speed, and limit the game package body Strict, the package body can include the main resources of the game, for example, the mini-game platform limits the size of the main package to no more than 4M; the file system interface, all mini-game platforms provide a set of exclusive file system interfaces, developers can use This interface is used for file management, including file addition, deletion, reading and writing, but the dedicated file system interface of each mini game platform is different, and the compatibility is relatively poor; the temporary file directory, when downloading resources on the mini game platform , if you do not specify the download cache path, the mini game platform will automatically download the files corresponding to the game resources to the temporary file directory, and the files stored in the temporary file directory only have read permission.
  • the mini game platform When exiting, the mini game platform will automatically clean up the files in the temporary file directory, which is not convenient for the secondary loading of resources; cache space, the mini game platform will allocate a certain storage space for each mini game.
  • a mini-game provides a 200M cache space, and the cache space will be reclaimed by the mini-game platform only when the mini-game is removed by the player.
  • the loading of game resources by the mini-game platform is used as an application scenario, and a resource data loading method is disclosed.
  • the mini-game platform can be built on the client 21 or the server 22 as shown in FIG. 2 Specifically, this embodiment is applicable to the case of resource data loading in the client 21, the method can be executed by a resource data loading device, the device can be implemented in software and/or hardware, and the device can be configured in Electronic devices, such as terminals, specifically include but are not limited to smartphones, handheld computers, tablet computers, wearable devices with display screens, desktop computers, notebook computers, all-in-one computers, smart home devices, and the like.
  • this embodiment can be applied to the situation where resource data is loaded in the server 22, and the method can be executed by a resource data loading device, which can be implemented in software and/or hardware, and which can be configured in an electronic device , such as a server. It can be understood that a method for reading resource data provided in the following embodiments can also be applied to the client 21 or the server 22 shown in FIG. 2 , which will not be repeated here.
  • a method for loading resource data provided by an embodiment of the present disclosure is applied to the scenario where a single resource of a game is loaded on a mini-game platform, and specifically includes the following steps S310 to S340:
  • each resource in the game has a globally unique tag value (ID/Universally Unique Identifier), which is also the file name when the resource is stored in the form of a file.
  • ID/Universally Unique Identifier is also the file name when the resource is stored in the form of a file.
  • the tag value of the obtained resource is analyzed to obtain the real path of the resource file storage, that is, the resource is located according to the resource name, and then, according to the real path of the resource, this A method for reading resource data provided by the disclosed embodiments reads the file corresponding to the resource in the temporary file directory into the memory.
  • a resource data loading method by obtaining the tag value of the resource to be processed, the resource in the temporary file directory is read into the memory according to the tag value, and the dependent resource list of the resource is further obtained, and loaded Rely on all the resources in the resource list, initialize them, complete the resource loading, and download the files corresponding to the resources to the temporary file directory.
  • the download speed is fast and the download time is short, thereby further shortening the loading time when the game starts for the first time.
  • FIG. 4 is a schematic flowchart of a resource data reading method provided by an embodiment of the present disclosure.
  • a cache list file is created in the cache space in advance, and the cache list file stores the cache list.
  • the cache list includes cache The identification field of the file, and the cache file is the file cached in the cache space.
  • each mini-game will be assigned a dedicated cache space, and different mini-games will store resource files in their respective cache spaces, and create a cache list file in each cache space for storing The cache list of their corresponding mini-games.
  • a cache list file (such as a cacheList.json file) is created in the cache space in advance, and the cache list file is used as a database of the cache space for recording information of each cache file in the cache space, and the information may include each cache The identification field of the file, where the identification field can specifically refer to the file name when the resource is stored in the form of a file.
  • the cache list in the memory can be obtained, and the cache list in the memory can be further queried. Directly obtain the information of each cache file in the cache space, and then determine the file names of all cache files included in the cache space.
  • the cache file refers to the file cached in the cache space.
  • This file can be called a cache file.
  • the cache list file is created in the cache space, it is not necessary to call the file system interface (readdir) every time the information of the cache file is queried. It only needs to call the file system when the game is loaded for the first time.
  • the interface only needs to read the cache list files stored in the cache space into the memory, which can increase the speed of querying cache file information, further reduce the loading time of the game, and can also quickly determine whether there are cache files to be processed stored in the cache space.
  • the resource data reading method shown in FIG. 4 specifically includes the following steps S410 to S440:
  • the resource to be read and the aforementioned cache space are for the same mini-game, and the path of the resource is obtained by analyzing the globally unique tag value of the resource, that is, the actual path of the resource in the file system. That is, the download address of the resource, a remote address such as a server, or a specific address in the local space.
  • the path of the resource can be a path concatenated according to the tag value of the resource.
  • the path of the resource is a remote path
  • the remote server address may be in the form of “https://example.com/remote/resources/...”.
  • After determining that the path is a remote path it is further judged whether the file corresponding to the resource is stored in the local space.
  • the local space includes a cache space and a temporary file directory, wherein the cache space and the resource to be read belong to the same mini game.
  • the file corresponding to the resource in the local space is read into the memory. That is to say, the path is not a remote path, that is, the path is a local path, indicating that the file corresponding to the resource is stored in the local space, and the file corresponding to the resource can be directly read from the local space to the memory without downloading.
  • the file corresponding to the resource is stored in the local space, read the file corresponding to the resource in the local space into the memory. That is to say, the path of the resource includes the address of the remote server, and it is determined as a remote path. Before determining as a remote path and downloading, it is necessary to determine whether the file corresponding to the resource is stored in the local space. If so, directly copy the file in the local space The file corresponding to the resource is read into memory.
  • the files corresponding to the resources downloaded to the temporary file directory are read into the memory, which is convenient for implementing the subsequent steps of game loading. Due to the characteristics of the temporary file directory, the files corresponding to the resources Less restrictions, faster loading speed, can further reduce the loading time of the game.
  • a resource data reading method provided by an embodiment of the present disclosure is to create a cache list file in the cache space in advance, wherein the cache list file stores the cache list, and the cache list stores the identifier field of the cache file, and the cache file is in Files cached in the cache space.
  • After generating the cache list file obtain the path of the resource to be read.
  • After determining that the path is a remote path further judge whether the file corresponding to the resource is stored in the local space. If not, download the resource through the remote path. file to the temporary file directory, and read the file from the temporary file directory into memory.
  • the cache list file can further determine whether the file is stored in the local space, and automatically download the file corresponding to the resource to the temporary file directory according to the remote path.
  • the download speed is fast and does not require User operations can automatically download the resource files to the temporary file directory, and then read the resource files from the temporary file directory into the memory, which can further reduce the game loading time.
  • FIG. 5 is a schematic flow diagram of a resource data reading method provided by an embodiment of the present disclosure.
  • the implementation process of reading the file corresponding to the resource into the memory through the path of the resource to be read specifically includes As shown in Figure 5, the following steps S510 to S550:
  • the path obtained by parsing the tag value of the resource to be read is obtained.
  • the path includes a pre-configured remote server address. If the path includes a pre-configured remote server address, it means that the path is a remote path. If the path does not include a pre-configured The configured remote server address indicates that the path is a local path.
  • the path is determined to be a remote path, it is further determined whether the file corresponding to the resource is stored in the local space, where the local space includes a cache space and a temporary file directory corresponding to the resource.
  • the file corresponding to the resource is not stored in the local space, that is, neither the cache space nor the temporary file directory stores the file corresponding to the resource, then the file corresponding to the resource is downloaded to the local space by accessing the remote address. in the temporary files directory.
  • the file corresponding to the resource downloaded to the temporary file directory is directly read into the memory.
  • the path is not a remote path, read the file corresponding to the resource into the memory.
  • the path is not a local path, it means that the corresponding file of the resource is stored in the local space, possibly stored in the cache space and/or the temporary file directory, and the resource corresponding to the resource is directly read in the local space files into memory.
  • the file corresponding to the resource exists in the local space, read the file corresponding to the resource into the memory.
  • the path is a remote path
  • the file corresponding to the resource may have been downloaded to the local space, but the path of the resource has not been updated or there is an abnormal situation such as crash.
  • FIG. 6 is a schematic flowchart of a method for reading resource data provided by an embodiment of the present disclosure.
  • the method further includes: The following steps S610 to S620 shown in FIG. 6:
  • the file system interface (access) provided by the mini game platform is usually used to determine whether the cache file is stored in the local space, or the file system interface (readdir) provided by the mini game platform is used in the game
  • the file system interface readdir
  • the game initialization time is proportional to the number of cached files, when the number of cached files in the cache space If there are too many, using the interface to directly read the information of all cache files in the cache space will consume a lot of reading time, that is, the more cache files are stored in the cache space, the longer the interface will take to read information, which will affect the game startup speed. Greater impact.
  • the content of the cache list file pre-established in the cache space of the mini game is read to obtain the cache list of the mini game.
  • the cache list obtained by the read operation is initialized into the memory, and the cache list file stores the information of each cache file in the current cache space, and is initialized into the memory for subsequent query of the cache list Content.
  • the cache list is initialized into the memory, it is determined whether the file corresponding to the resource is stored in the local space, including:
  • Judging whether the file corresponding to the resource is stored in the cache space or the temporary file directory; among them, judging whether the file corresponding to the resource is stored in the cache space includes: querying the identifier field of the cache file in the cache list in memory; if the resource is queried If the identifier of the corresponding file is used, it is determined that the file corresponding to the resource is stored in the cache space.
  • the cache list in the memory can be directly queried If the identification field of each cache file in the cache file is found, if the identification of the file corresponding to the resource is found, it is determined that the file corresponding to the resource is stored in the cache space. At the same time, it can also be queried through the file system interface whether the temporary file directory contains the corresponding resource. document.
  • the resource data reading method provided by the embodiment of the present disclosure obtains the cache list in the memory by reading the pre-created cache list file in the cache space, and can directly obtain the information of the cache file by querying the cache list without multiple times Calling the file system interface to query the information of the cached files included in the cache space can effectively reduce the time for obtaining information and facilitate operations such as downloading or reading subsequent resources.
  • Fig. 7 is a schematic flowchart of a method for reading resource data provided by an embodiment of the present disclosure.
  • the method further includes: The following steps S710 to S740:
  • the following method is usually adopted, directly downloading the file corresponding to the resource to the cache space and then reading the file, or directly downloading the file of the resource to Temporary file directory, then copied to the cache space and then read the files in the cache space; using the method of directly downloading to the cache space, not only the cache space needs to be specified in advance, but also limited by the cache space, and cannot be stored in the cache space It will cause resource download failure, which will affect the normal operation of the game. It is necessary to re-download resources after clearing the cache space.
  • the loading time at the first cold start is one of the important indicators to measure the game, that is, the startup time of the mini-game when it has just been downloaded and there is no cache file in the local space.
  • the generated cache tasks are added to the cache queue, wherein the cache queue is a queue created in the memory, and the cache tasks are executed one by one according to the information included in the cache tasks arranged in the cache queue .
  • the cache tasks to be processed can be obtained according to the first-in-first-out acquisition principle, for example, adding cache tasks at the end of the cache queue, The first part of the cache task.
  • the temporary file directory has the characteristics of unlimited download file size and fast download speed
  • the files that need to be downloaded are directly downloaded to the temporary file directory, and then the files that are directly read into the memory are also from the temporary file directory, not in the cache space
  • the operation of reading from the temporary file directory and copying to the cache space can be performed at the same time, at this time, the file when the copy operation is performed may not be the currently read file, for example,
  • the cache queue in the memory includes 4 cache tasks, and the cache task generated by the downloaded file is the fifth cache task in the cache queue, so it is executed simultaneously with the read operation It may be the file corresponding to the first cache task; or, first perform the read operation from the temporary file directory, and then, after the preset time, copy the read resource file to the cache space, that is, , the read operation is performed first and then the copy operation is performed. Because of the read-only nature of the temporary file directory, the file needs to be stored in the cache space to facilitate subsequent loading of
  • the method further includes:
  • the identifier of the cache file corresponding to the cache task in the cache space is recorded in the identifier field of the cache file in the cache list in the memory, wherein the identifier may include the name of the cache file, that is to say , after the file corresponding to the resource is downloaded to the temporary file directory, a cache task including the file information will be generated, and then the file will be copied to the cache space according to the cache task, and the file name of the file will be obtained and recorded in the cache list in the memory , to obtain the updated cache list; the cache list file can be updated in time after the preset time according to the updated cache list, wherein the preset time can be 200ms, and the cache list file can be understood as a subclass of the real cache list in memory Set, that is to say, the number of information included in the cache list file may be less than or equal to the number of information in the cache list, there will be a cache list update, but the cache list file has not been updated, at this time, the cache task to
  • a resource data reading method provided by an embodiment of the present disclosure downloads a file corresponding to a resource into a temporary file directory and generates a cache task including the file information, and directly reads the file in the temporary file directory into the memory, Then copy the file from the temporary file directory to the cache space according to the cache task, the download speed to the temporary file directory is fast, and the limit on the file size is relatively small, which can effectively reduce the reading time of resource files and further reduce Loading time on first cold start.
  • FIG. 8 is a schematic flowchart of a resource data reading method provided by an embodiment of the present disclosure.
  • the file corresponding to the resource does not exist in the local space, it specifically includes the method shown in FIG. 8
  • the file corresponding to the resource is downloaded to the temporary file directory.
  • a cache task including file information corresponding to the resource is generated, and the cache task is added to the cache queue in the memory.
  • the file corresponding to the resource downloaded to the temporary file directory can be directly read into the memory to complete the resource reading operation.
  • the file corresponding to the cache task that is, the file previously downloaded to the temporary file directory, is copied into the cache space.
  • the preset period can be set to 500ms, that is, the files in a temporary file directory will be copied to the cache space after 500ms.
  • the resource data reading method provided by the embodiment of the present disclosure adopts the method of reading first and then copying, which can not only ensure that the loading time of the first cold start is short enough, but also continuously increase with the use time of the game.
  • the files in the temporary file directory are copied to the cache space in a timely manner, thereby reducing the loading time of opening the game multiple times.
  • FIG. 9 is a schematic structural diagram of a resource data loading device provided by an embodiment of the present disclosure.
  • the resource data loading device 900 specifically includes:
  • the first acquiring module 910 is configured to acquire the tag value of the resource to be processed
  • the first reading module 920 is used to read the file corresponding to the resource into the memory by using the above-mentioned resource data reading device according to the tag value;
  • the dependency module 930 is configured to obtain a list of dependent resources according to the files corresponding to the resources;
  • the loading module 940 is configured to load the dependent resources in the dependent resource list and perform initialization to obtain loaded resource data.
  • the resource data loading device of the embodiment shown in FIG. 9 can be used to implement the technical solution of the above-mentioned method embodiment, and its implementation principle and technical effect are similar, and will not be repeated here.
  • FIG. 10 is a schematic structural diagram of a resource data reading device provided by an embodiment of the present disclosure.
  • a cache list file is created in the cache space in advance, and the cache list file stores the cache list.
  • the cache list includes the identification field of the cache file, and the cache file is For files cached in the cache space, the resource data reading device 1000 specifically includes:
  • An acquisition module 1100 configured to acquire the path of the resource to be read, wherein the path is obtained by parsing the tag value corresponding to the resource;
  • the judging module 1200 is configured to judge whether the file corresponding to the resource is stored in the local space after determining that the path is a remote path, and the local space includes a cache space and a temporary file directory;
  • the download module 1300 is used to download the file corresponding to the resource to the temporary file directory according to the remote path if the file corresponding to the resource is not stored in the local space;
  • the reading module 1400 is configured to read the files corresponding to the resources in the temporary file directory into the memory.
  • the resource data reading device 1000 also includes a first reading module, which is used to: before judging whether the file corresponding to the resource is stored in the local space, specifically:
  • determine whether the file corresponding to the resource is stored in the local space including:
  • Judging whether the file corresponding to the resource is stored in the cache space or the temporary file directory; among them, judging whether the file corresponding to the resource is stored in the cache space includes: querying the identifier field of the cache file in the cache list in memory; if the resource is queried If the identifier of the corresponding file is used, it is determined that the file corresponding to the resource is stored in the cache space.
  • the resource data reading device 1000 also includes a generation module, and the generation module is used to download the file corresponding to the resource into the temporary file directory according to the remote path, and is specifically used for:
  • the cache queue in the generation module includes one or more cache tasks, and the generation module is also used to add the cache tasks to the cache queue, specifically for:
  • the resource data reading device 1000 also includes an update module, which is used to: after the file corresponding to the cache task is successfully copied from the temporary file directory to the cache space, the update module is specifically used to:
  • the resource data reading device of the embodiment shown in FIG. 10 can be used to implement the technical solution of the above-mentioned method embodiment, and its implementation principle and technical effect are similar, and will not be repeated here.
  • Fig. 11 is a schematic structural diagram of an electronic device provided by an embodiment of the present disclosure.
  • the electronic device may be the above server or terminal.
  • the electronic device provided by the embodiments of the present disclosure can execute the processing flow of resource data loading provided by the above embodiments, or the processing flow of resource data reading provided by the above embodiments.
  • the electronic device 1110 includes: a processor 1120 , a communication interface 1130 and a memory 1140; wherein, the computer program is stored in the memory 1140 and is configured to be executed by the processor 1120 as the resource data loading method or the resource data reading method described above.
  • an embodiment of the present disclosure also provides a computer-readable storage medium, on which a computer program is stored, and the computer program is executed by a processor to implement the method for loading resource data or the method for reading resource data in the foregoing embodiments.
  • an embodiment of the present disclosure also provides a computer program product, where the computer program product includes a computer program or an instruction, and when the computer program or instruction is executed by a processor, implements the resource data loading method or the resource data reading method described above .
  • the computer program product can write program codes for executing the operations of the embodiments of the present disclosure in any combination of one or more programming languages, and the programming languages include object-oriented programming languages, such as Java, C++, etc., and Included are conventional procedural programming languages, such as the "C" language or similar programming languages.
  • the program code may execute entirely on the user's computing device, partly on the user's device, as a stand-alone software package, partly on the user's computing device and partly on a remote computing device, or entirely on the remote computing device or server to execute.

Abstract

本公开提供了一种资源数据读取方法、装置、电子设备和存储介质,其中,方法包括:预先在缓存空间中创建缓存列表文件,缓存列表文件用于存储缓存空间中各缓存文件的标识信息,在创建完缓存列表文件后,获取待读取的资源的路径,在确定路径为远程路径后,进一步判断资源对应的文件是否存储在本地空间中,若没有存储在本地,则通过远程路经下载该文件至临时文件目录中,并从临时文件目录中读取该文件到内存中。

Description

一种资源数据读取方法、装置、电子设备和存储介质
本公开要求于2021年07月02日提交中国专利局、申请号为202110750353.3、发明名称为“一种资源数据读取方法、装置和存储介质”的中国专利申请的优先权,该申请的全文以引用的方式并入本文中。
技术领域
本公开实施例涉及数据处理技术领域,具体涉及一种资源数据读取方法、装置、电子设备和存储介质。
背景技术
随着多媒体技术的飞速发展,部署在终端或网页上的小游戏平台,因操作简单、游戏种类多和无需安装等特点使得其应用广泛,因此,在小游戏平台上对游戏资源进行下载和读取就至关重要,目前,多是通过用户操作将游戏资源下载到缓存空间中,下载到缓存空间中需要用户指定缓存路径,操作繁琐,且游戏加载过程中包括的将资源下载到缓存空间以及读取缓存空间内资源等操作,会使得游戏加载时间过长,不便于快速的打开游戏,用户体验较差。
发明内容
第一方面,本公开实施例提供了一种资源数据读取方法,预先在缓存空间中创建缓存列表文件,缓存列表文件中存储缓存列表,缓存列表包括缓存文件的标识字段,缓存文件为缓存在缓存空间中的文件,方法包括:
获取待读取的资源的路径,其中,路径通过解析资源对应的标签值得到;
在确定路径为远程路径后,判断资源对应的文件是否存储在本地空间中,本地空间包括缓存空间和临时文件目录;
若资源对应的文件未存储在本地空间中,则根据远程路径,将资源对应的文件下载到临时文件目录中;
将临时文件目录中资源对应的文件读取到内存中。
第二方面,本公开实施例提供了一种资源数据加载方法,包括:
获取待处理的资源的标签值;
根据标签值,采用上述资源数据读取方法读取资源对应的文件到内存中;
根据资源对应的文件,得到依赖资源列表;
加载依赖资源列表中的依赖资源,并进行初始化,得到加载后的资源数据。
第三方面,本公开实施例提供了一种资源数据读取装置,预先在缓存空间中创建缓存列表文件,缓存列表文件中存储缓存列表,缓存列表包括缓存文件的标识字段,缓存文件为缓存在缓存空间中的文件,方法包括:
获取模块,用于获取待读取的资源的路径,其中,路径通过解析资源对应的标签值得到;
判断模块,用于在确定路径为远程路径后,判断资源对应的文件是否存储在本地空间中,本地空间包括缓存空间和临时文件目录;
下载模块,用于若资源对应的文件未存储在本地空间中,则根据远程路径,将资源对应的文件下载到临时文件目录中;
读取模块,用于将临时文件目录中资源对应的文件读取到内存中。
第四方面,本公开实施例提供了一种资源数据加载装置,包括:
第一获取模块,用于获取待处理的资源的标签值;
第一读取模块,用于根据标签值,采用上述资源数据读取装置读取资源对应的文件到内存中;
依赖模块,用于根据资源对应的文件,得到依赖资源列表;
加载模块,用于加载依赖资源列表中的依赖资源,并进行初始化,得到加载后的资源数据。
第五方面,本公开实施例提供了一种电子设备,包括:
处理器;以及
存储器,用于存储可在处理器上运行的计算机程序,处理器执行计算机程序时实现上述的资源数据读取方法。
第六方面,本公开实施例提供了一种电子设备,包括:
处理器;以及
存储器,用于存储可在处理器上运行的计算机程序,处理器执行计算机程序时实现上述的资源数据加载方法。
第七方面,本公开实施例提供了一种计算机可读存储介质,其上存储有计算机程序,计算机程序被处理器执行时实现如上述的资源数据读取方法的步骤,或者用于上述的资源数据加载方法。
附图说明
为了更清楚地说明本公开实施例的技术方案,下面将对实施例或现有技术描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本公开的一些实施例,对于本领域普通技术人员来讲,还可以根据这些附图获得其他的附图。
图1为本公开实施例提供的一种资源存储形式的示意图;
图2为本公开实施例提供的一种应用场景的示意图;
图3为本公开实施例提供的一种资源数据加载方法的流程示意图;
图4为本公开实施例提供的一种资源数据读取方法的流程示意图;
图5为本公开实施例提供的一种资源数据加载方法的流程示意图;
图6为本公开实施例提供的一种资源数据读取方法的流程示意图;
图7为本公开实施例提供的一种资源数据读取方法的流程示意图;
图8为本公开实施例提供的一种资源数据读取方法的流程示意图;
图9为本公开实施例提供的一种资源数据加载装置的结构示意图;
图10为本公开实施例提供的一种资源数据读取装置的结构示意图;
图11为本公开实施例提供的一种电子设备的结构示意图。
具体实施方式
为了能够更清楚地理解本公开的上述目的、特征和优点,下面结合附图和实施例对本公开作进一步的详细说明。可以理解的是,所描述的实施例是本公开的一部分实施例,而不是全部的实施例。此处所描述的具体实施例仅仅用于解释本公开,而非对本公开的限定。基于所描述的本公开的实施例,本领域普通技术人员所获得的所有其他实施例,都属于本公开保护的范围。
需要说明的是,在本文中,诸如“第一”和“第二”等之类的关系术语仅仅用来将一个实体或者操作与另一个实体或操作区分开来,而不一定要求或者暗示这些实体或操作之间存在任何这种实际的关系或者顺序。
本公开实施例提供的一种资源数据读取方法,预先在缓存空间中创建缓存列表文件,缓存列表文件中存储缓存列表,缓存列表中存有缓存文件的标识字段,缓存文件为在缓存空间中缓存的文件,获取待读取的资源的路径,在确定路径为远程路径后,进一步判断资源对应的文件是否存储在本地空间中,若没有存储在本地,则通过远程路经下载该文件至临时文件目录中,并从临时文件目录中读取该文件到内存中。在资源的路径为远程路径的情况下,不需要频繁多次调用文件系统接口,就能够判断本地空间是否存储该文件,并根据远程路径自动下载资源对应的文件至临时文件目录中,下载速度较快,且不需要用户操作即可自动下载资源文件,下载至临时文件目录中便于将资源文件读取到内存中。
具体的,游戏由各类资源组成,资源可以理解为数据的结合体,是游戏的基本组成元素,控制游戏的实现,例如,资源具体可以指游戏场景、模型、音频、视频、文本和纹理等,在游戏的使用过程中,所有被使用到的各类资源会以文件的形式导出到系统文件中,并且资源会以全局中唯一的标识(名 称)进行命名,示例性的,以图1中所示的各种资源的命名表现形式为例,各类资源以文件的形式存在且拥有唯一对应的文件名称,图1中系统文件包括的各资源对应的文件可以分为road、tree以及car,以及各文件中包括的子文件,road01和car101等。
具体的,上述游戏资源可以在小游戏平台进行加载,小游戏平台在资源管理方面的特点包括:包体限制,小游戏平台为了减少游戏加载的时间,加快游戏启动速度,对游戏包体的限制比较严格,包体可以包括游戏的主要资源,例如,小游戏平台限制主包的大小不能超过4M大小;文件系统接口,所有小游戏平台都提供了一套专属的文件系统接口,开发者可以使用该接口进行文件管理,包括文件的增、删、读和写,但每个小游戏平台的专属文件系统接口又各不相同,兼容性比较差;临时文件目录,在小游戏平台上下载资源时,如果不指定下载的缓存路径,则小游戏平台会将游戏资源对应的文件自动下载到临时文件目录中,临时文件目录中存储的文件只有读权限,虽然临时目录不限制大小,但是在小游戏退出时小游戏平台会自动清理临时文件目录中的文件,不便于资源的二次加载;缓存空间,小游戏平台会分配给每个小游戏一定存储空间的缓存空间,例如,小游戏平台为每个小游戏提供了200M的缓存空间,只有在小游戏被玩家移除时,缓存空间才会被小游戏平台所回收。
具体的,在下述实施例中以小游戏平台加载游戏资源为应用场景,公开一种资源数据加载方法,可理解的,小游戏平台可以架构在如图2所示的客户端21或服务端22中,具体的,本实施例可适用于客户端21中进行资源数据加载的情况,该方法可以由资源数据加载装置执行,该装置可以采用软件和/或硬件的方式实现,该装置可配置于电子设备中,例如终端,具体包括但不限于智能手机、掌上电脑、平板电脑、带显示屏的可穿戴设备、台式机、笔记本电脑、一体机、智能家居设备等。或者,本实施例可适用于服务端22中进行资源数据加载的情况,该方法可以由资源数据加载装置执行,该装置可以采用软件和/或硬件的方式实现,该装置可配置于电子设备中,例如服务器。可理解的,下述实施例提供的一种资源数据读取方法同样可以应用在如图2所示的客户端21或服务端22中,在此不作赘述。
在一个实施例中,如图3所示,本公开实施例提供的一种资源数据加载方法,应用于小游戏平台加载游戏的单个资源的场景下,具体包括如下步骤S310至S340:
S310、获取待处理的资源的标签值。
可理解的,在游戏中每个资源均存在全局唯一标签值(ID/Universally Unique Identifier),该标签值同时也是资源以文件形式存储时的文件名称。
S320、根据标签值,读取资源对应的文件到内存中。
可理解的,在上述S310到的基础上,对获取的资源的标签值进行解析,得到资源文件存储的真实路径,也就是根据资源名称对资源进行定位,随后,根据资源的真实路径,采用本公开实施例提供的一种资源数据读取方法将临时文件目录中该资源对应的文件读取到内存中。
S330、根据资源对应的文件,得到依赖资源列表。
可理解的,在上述S320的基础上,将读取到内存中的资源对应的文件反序列化为资源对象,并确定该资源的依赖资源的标识(UUID)列表,其中,该资源的依赖资源是指该资源的应用需要从周围环境中吸取资源,需要与周围环境相互依存、相互作用才能达到目的,也就是确保该资源正常应用所需要的其他资源;UUID(Universally Unique Identifier)是指全局唯一标识符(识别符),资源的UUID能过保证在同一空间中的所有资源都是唯一的。
S340、加载依赖资源列表中的依赖资源,并进行初始化,得到加载后的资源数据。
可理解的,在上述S330的基础上,加载依赖资源列表中的所有资源,在依赖资源列表中所有资源加载完成后,将所有资源进行初始化操作并初始化到内存中,此时内存中初始化后的所有资源为该资源的完整可用资源。
本公开实施例提供的一种资源数据加载方法,通过获取待处理的资源的标签值,根据标签值将临时文件目录中的该资源读取到内存中,进一步获取该资源的依赖资源列表,加载依赖资源列表中的所有资源,并进行初始化,完成资源的加载,将该资源对应的文件下载到临时文件目录中下载速度快且下载时间短,从而进一步缩短游戏第一次启动时的加载时间,提高用户体验。
在上述实施例的基础上,图4为本公开实施例提供的一种资源数据读取方法的流程示意图,预先在缓存空间中创建缓存列表文件,缓存列表文件中存储缓存列表,缓存列表包括缓存文件的标识字段,缓存文件为缓存在缓存空间中的文件。
可理解的,在小游戏平台中,会为每个小游戏分配专属的缓存空间,不同小游戏会在各自的缓存空间中存储资源文件,在各个缓存空间中均创建缓存列表文件,用于存储各自对应的小游戏的缓存列表。
可理解的,预先在缓存空间中创建缓存列表文件(例如为cacheList.json文件),将缓存列表文件作为缓存空间的数据库,用于记录缓存空间中各缓存文件的信息,该信息可以包括各缓存文件的标识字段,其中,标识字段具体可以指资源以文件形式进行存储时的文件名称,通过读取缓存空间中的缓存列表文件,得到内存中的缓存列表,进一步查询内存中的缓存列表,能够直接获取缓存空间中各缓存文件的信息,进而确定该缓存空间中包括的所有缓存文件的文件名称,缓存文件是指在缓存空间 中缓存的文件,例如,资源对应的文件存储在缓存空间后,该文件可以称为缓存文件,在缓存空间中创建缓存列表文件后,不需要在每次查询缓存文件的信息时都调用文件系统接口(readdir),只需要在游戏第一次加载时调用文件系统接口将缓存空间中存储的缓存列表文件读取到内存中即可,能够提高查询缓存文件信息的速度,进一步减少游戏的加载时间,同时也能快速判断缓存空间中是否存储待处理的缓存文件。
图4所示的资源数据读取方法具体包括如下步骤S410至S440:
S410、获取待读取的资源的路径,其中,路径通过解析资源对应的标签值得到。
可理解的,待读取的资源与前述缓存空间针对的是同一个小游戏,通过对该资源的全局唯一标签值进行解析,得到该资源的路径,即该资源在文件系统中的实际路径,也就是该资源的下载地址,在服务器等远端的地址或本地空间中的具体地址,可选的,该资源的路径可以是根据资源的标签值拼接出来的路径。
S420、在确定路径为远程路径后,判断资源对应的文件是否存储在本地空间中,本地空间包括缓存空间和临时文件目录。
可理解的,以上述S410的基础上,判断资源的路径是否远程路径,可以通过判断该路径是否包含远程服务器地址来确定该资源的路径是否为远程路径,其中,可以预先设置多个远程服务器地址,进一步判断该资源的路径中是否包括设置的远程服务器地址,例如,远程服务器地址可以为“https://example.com/remote/resources/…”的形式。在确定路径为远程路径后,进一步判断该资源对应的文件是否存储在本地空间中,本地空间包括缓存空间和临时文件目录,其中,缓存空间与待读取的资源属于同一个小游戏。
可选的,若确定路径不是远程路径,则将本地空间中资源对应的文件读取到内存中。也就是说,该路径不是远程路径,即该路径为本地路径,表明该资源对应的文件存储在本地空间中,无需下载即可直接从本地空间中读取该资源对应的文件到内存中。
S430、若资源对应的文件未存储在本地空间中,则根据远程路径,将资源对应的文件下载到临时文件目录中。
可理解的,在上述S420的基础上,通过判断若确定资源对应的文件未存储在本地空间中,则根据远程路径,直接将资源对应的文件下载到临时文件目录中,也就是,直接访问远程路径包括的远程服务器,并在该服务器包括的资源对应的文件下载到临时文件目录中。
可选的,若资源对应的文件存储在本地空间中,则将本地空间中资源对应的文件读取到内存中。 也就是说,该资源的路径包含远程服务器地址,确定为远程路径,在确定为远程路径以及在下载之前,需要判断本地空间中是否存储该资源对应的文件,若是,则直接将本地空间中该资源对应的文件读取到内存中。
S440、将临时文件目录中资源对应的文件读取到内存中。
可理解的,在上述S430的基础上,将下载至临时文件目录中的资源对应的文件读取到内存中,便于实施游戏加载的后续步骤,由于临时文件目录的特性,对资源对应的文件的限制少,读取速度比较快,能够进一步减少游戏的加载时间。
本公开实施例提供的一种资源数据读取方法,通过预先在缓存空间中创建缓存列表文件,其中,缓存列表文件中存储缓存列表,缓存列表中存有缓存文件的标识字段,缓存文件为在缓存空间中缓存的文件。在生成缓存列表文件后,获取待读取的资源的路径,在确定路径为远程路径后,进一步判断资源对应的文件是否存储在本地空间中,若没有存储在本地,则通过远程路经下载该文件至临时文件目录中,并从临时文件目录中读取该文件到内存中。在资源的路径为远程路径的情况下,通过缓存列表文件就能进一步判断本地空间是否存储该文件,并根据远程路径自动下载资源对应的文件至临时文件目录中,下载速度较快,且不需要用户操作即可自动下载资源文件至临时文件目录中,随后,在临时文件目录中读取资源文件到内存中,能够进一步减少游戏加载时间。
图5为本公开实施例提供的一种资源数据读取方法的流程示意图,在上述实施例的基础上,通过待读取的资源的路径读取资源对应的文件到内存中的实现流程具体包括如图5所示的如下步骤S510至S550:
S510、获取待读取的资源的路径。
可理解的,获取由待读取的资源的标签值解析得到的路径。
S520、判断路径是否是远程路径。
可理解的,通过判断该路径是否包括预先配置的远程服务器地址进而判断该路径是否是远程路径,若该路径包括预先配置的远程服务器地址,则说明该路径为远程路径,若该路径不包括预先配置的远程服务器地址,则说明该路径为本地路径。
S530、若路径是远程路径,则判断本地空间是否存在该资源对应的文件。
可理解的,在确定路径是远程路径的情况下,进一步判断本地空间中是否存储该资源对应的文件,其中,本地空间包括与资源对应的缓存空间和临时文件目录。
S540、若本地空间不存在该资源对应的文件,则将该资源对应的文件下载到临时文件目录中。
可理解的,若本地空间中没有存储该资源对应的文件,即缓存空间和临时文件目录中均未存储该资源对应的文件,则通过访问远程地址将该资源对应的文件下载到本地空间中的临时文件目录中。
S550、读取该资源对应的文件到内存中。
可理解的,直接读取下载到临时文件目录中的该资源对应的文件到内存中。
可选的,若路径不是远程路径,则读取该资源对应的文件到内存中。
可理解的,若确定该路径未本地路径,则说明该资源的对应的文件存储在本地空间中,可能存储在缓存空间和/或临时文件目录中,则直接在本地空间中读取该资源对应的文件到内存中。
可选的,若本地空间存在该资源对应的文件,则读取该资源对应的文件到内存中。
可理解的,在确定该路径是远程路径后,进一步判断本地空间中是否存在该资源对应的文件,若本地空间中存在该资源对应的文件,则直接在本地空间中读取该资源对应的文件到内存中,此种情况可能是已经将该资源对应的文件下载至本地空间中,但该资源的路径尚未更新或出现闪退等不正常的情况。
在上述实施例的基础上,图6为本公开实施例提供的一种资源数据读取方法的流程示意图,可选的,在判断资源对应的文件是否存储在本地空间中之前,方法还包括如图6所示的如下步骤S610至S620:
具体的,现阶段,在小游戏平台中通常利用其本身提供的文件系统接口(access)来判断缓存文件是否存储在本地空间中,或,利用小游戏平台提供的文件系统接口(readdir)在游戏启动时将缓存空间中的所有缓存文件的信息逐一读取出来生成列表,进而通过列表判断是否包括缓存文件;通过access接口进行判断,虽然简单直接,但是每次调用access接口将耗费2-3ms的时长,当加载资源的数量较多时将耗费大量时间进行判断,导致游戏的加载时间过长;通过readdir接口进行判断时,游戏初始化时间与已缓存的文件数量成正比,当缓存空间中缓存文件数量过多时,利用接口直接读取缓存空间中所有缓存文件的信息,将会耗费大量的读取时间,即缓存空间中存储的缓存文件越多,接口读取信息的时间越长,对游戏启动速度影响较大。
S610、读取缓存空间中缓存列表文件的内容,得到缓存列表。
可理解的,在小游戏启动时,读取在该小游戏的缓存空间中预先建立的缓存列表文件的内容,得到该小游戏的缓存列表。
S620、将缓存列表初始化到内存中。
可理解的,在上述S610的基础上,将读取操作得到的缓存列表初始化到内存中,该缓存列表文 件存储的是当前缓存空间中各缓存文件的信息,初始化到内存中便于后续查询缓存列表的内容。
可选的,在将缓存列表初始化到内存中后,判断资源对应的文件是否存储在本地空间中,包括:
判断资源对应的文件是否存储在缓存空间中或临时文件目录中;其中,判断资源对应的文件是否存储在缓存空间中,包括:在内存中查询缓存列表中缓存文件的标识字段;若查询到资源对应的文件的标识,则确定资源对应的文件存储在缓存空间中。
可理解的,将缓存列表初始化到内存中后,进一步判断资源对应的文件是否存储在缓存空间或临时文件目录中,或者二者中均存储了资源对应的文件,可以直接查询内存中的缓存列表中各缓存文件的标识字段,若查询到该资源对应的文件的标识,则确定该资源对应的文件存储在缓存空间中,同时也可以通过文件系统接口查询临时文件目录中是否包括该资源对应的文件。
本公开实施例提供的一种资源数据读取方法,通过读取缓存空间中预先创建的缓存列表文件,得到内存中的缓存列表,可以直接通过查询缓存列表获取缓存文件的信息,不需要多次调用文件系统接口来查询缓存空间中包括的缓存文件的信息,能够有效减少信息的获取时间,便于对后续资源进行下载或读取等操作。
图7为本公开实施例提供的一种资源数据读取方法的流程示意图,可选的,在根据远程路径,将资源对应的文件下载到临时文件目录中之后,方法还包括如图7所示的如下步骤S710至S740:
具体的,现阶段,在小游戏平台中进行资源的下载和读取时,通常采用如下方法,将资源对应的文件直接下载到缓存空间中再读取文件,或,将资源的文件直接下载到临时文件目录中,随后复制到缓存空间中再读取缓存空间中的文件;采用直接下载到缓存空间中的方法,不仅需要提前指定缓存空间,还受到缓存空间的限制,且在缓存空间无法存储时将会造成资源下载失败,下载失败将会影响游戏正常运行,需要清理缓存空间后重新下载资源,要成功下载资源,操作步骤以及限制比较多,用户体验差;现有技术中,将资源下载到临时文件目录后会马上将该资源复制到缓存空间中,随后在缓存空间中读取该资源,同时存在下载以及复制文件等两个操作,操作繁琐,且在第一次启动游戏时,会造成第一次冷启动时的加载时间过长,用户体验差。其中,第一次冷启动时的加载时间是衡量游戏的重要指标之一,即小游戏在刚下载完成,本地空间没有任何缓存文件的情况下的启动耗时。
S710、并生成与下载到临时文件目录中的文件对应的缓存任务。
可理解的,在确定本地空间不包括资源对应的文件后,需要根据远程路径下载该资源对应的文件,将资源对应的文件下载到本地空间中的临时文件目录中,同时根据文件的下载操作生成包括该资源对应的文件信息的缓存任务。
S720、将缓存任务添加到缓存队列中,缓存队列为在内存中创建的队列。
可理解的,在上述S710的基础上,将生成的缓存任务添加到缓存队列中,其中,缓存队列是在内存中创建的队列,按照缓存队列中排列的缓存任务所包括的信息逐一执行缓存任务。
S730、获取内存中缓存队列中的缓存任务。
可理解的,在上述S720的基础上,按照缓存队列中缓存任务的排列顺序获取当前待处理的缓存任务,可以采用先进先出的获取原则,例如,在缓存队列的尾部添加缓存任务,在队列的首部获取缓存任务。
S740、将缓存任务对应的文件从临时文件目录中复制到缓存空间中。
可理解的,在上述S730的基础上,根据缓存任务包括的信息执行相应的操作,将下载到临时文件目录中的待读取资源对应的文件复制到缓存空间中,复制到缓存空间中后便于后续游戏的加载,在重新运行游戏时能够减少加载时间。
可理解的,因为临时文件目录具有的不限制下载文件大小以及下载速度快的特性,对于需要下载的文件是直接下载到临时文件目录中的,随后直接读取到内存中的文件也是从临时文件目录中读取的,而不是缓存空间中,从临时文件目录中读取操作与复制到缓存空间的操作可以同时执行,此时,复制操作执行时的文件可能不是当前读取的文件,例如,将资源对应的文件下载到临时文件目录中时,内存中的缓存队列包括4个缓存任务,该下载文件生成的缓存任务为缓存队列中的第5个缓存任务,因此,和读取操作同时执行的可能是第1个缓存任务对应的文件;或者,先执行从临时文件目录中的读取操作,随后,在预设时间后,将该读取的资源的文件复制到缓存空间中,也就是,先进行读取操作随后进行复制操作,因为临时文件目录的只读特性,因此,需要将文件存储到缓存空间中,便于后续对该资源的加载。
可选的,在缓存任务对应的文件从临时文件目录中成功复制到缓存空间后,方法还包括:
将缓存空间中与缓存任务对应的缓存文件的标识记录到内存中缓存列表的缓存文件的标识字段,得到更新后的缓存列表;将更新后的缓存列表写入缓存列表文件中。
可理解的,复制操作执行完成后,将缓存空间中与缓存任务对应的缓存文件的标识记录到内存中缓存列表中缓存文件的标识字段,其中,标识可以包括该缓存文件的名称,也就是说,资源对应的文件下载到临时文件目录中后会生成包括该文件信息的缓存任务,随后根据缓存任务将该文件复制到缓存空间中,同时获取该文件的文件名称并记录到内存中的缓存列表中,得到更新后的缓存列表;可以根据更新后的缓存列表在预设时间后及时更新缓存列表文件,其中,预设时间可以为200ms,缓存列 表文件可以理解为是内存中真实缓存列表的子集,也就是说,缓存列表文件包括的信息的数量可能小于或等于缓存列表中信息的数量,会存在缓存列表更新,但缓存列表文件还没有更新的情况,此时,待处理的缓存任务对应的文件的信息全部更新完成,更新后的缓存列表中就包括了该文件的标识字段。
本公开实施例提供的一种资源数据读取方法,将资源对应的文件下载到临时文件目录中并生成包括该文件信息的缓存任务,直接将临时文件目录中的该文件读取到内存中,随后根据缓存任务将该文件从临时文件目录中复制到缓存空间中,下载到临时文件目录中的下载速度快,且对文件大小的限制比较小,能够有效减少资源文件的读取时间,进一步减少第一次冷启动时的加载时间。
在上述实施例的基础上,图8为本公开实施例提供的一种资源数据读取方法的流程示意图,应用在本地空间不存在该资源对应的文件的情况下,具体包括如图8所示的如下步骤S810至S860:
S810、将资源对应的文件下载到临时文件目录中。
可理解的,根据该资源的远程路径,将该资源对应的文件下载到临时文件目录中。
S820、生成缓存任务,并将缓存任务添加到缓存队列中。
可理解的,根据下载操作,生成包括资源对应的文件信息的缓存任务,并将缓存任务添加到内存中的缓存队列中。
S830、读取临时文件目录中资源对应的文件到内存中。
可理解的,生成缓存任务后,即可直接读取下载到临时文件目录中的该资源对应的文件到内存中,完成资源读取操作。
S840、获取缓存任务。
可理解的,获取内存中缓存队列中当前待处理的缓存任务,此时,图8所示的情况中,采用先进先出的获取原则,此时,获取的缓存任务中对应的文件与读取的文件不同。
S850、将缓存任务对应的文件从临时文件目录复制到缓存空间。
可理解的,将缓存任务对应的文件,也就是之前下载到临时文件目录中的文件复制到缓存空间中。
S860、判断缓存队列中存在未处理的缓存任务。
可理解的,判断当前获取并处理的缓存任务是否是缓存队列中排列的最后一个缓存任务,若是,则结束复制操作的流程;若缓存队列中还存在尚未复制的缓存任务,则在预设周期后继续获取缓存任务,执行复制操作的流程,其中,预设周期可以设置为500ms,即经过500ms后将一个临时文件目录中的文件复制到缓存空间中。
本公开实施例提供的一种资源数据读取方法,采用先读取后复制的方法,既能在保证第一次冷启动加载时间足够短的情况下,随着游戏使用时间的增加,会不断地将临时文件目录中的文件复制到缓存空间中,从而降低多次打开游戏的加载时间。
在上述实施例的基础上,图9为本公开实施例提供的一种资源数据加载装置的结构示意图,资源数据加载装置900具体包括:
第一获取模块910,用于获取待处理的资源的标签值;
第一读取模块920,用于根据标签值,采用上述资源数据读取装置读取资源对应的文件到内存中;
依赖模块930,用于根据资源对应的文件,得到依赖资源列表;
加载模块940,用于加载依赖资源列表中的依赖资源,并进行初始化,得到加载后的资源数据。
图9所示实施例的资源数据加载装置可用于执行上述方法实施例的技术方案,其实现原理和技术效果类似,此处不再赘述。
图10为本公开实施例提供的一种资源数据读取装置的结构示意图,预先在缓存空间中创建缓存列表文件,缓存列表文件中存储缓存列表,缓存列表包括缓存文件的标识字段,缓存文件为缓存在缓存空间中的文件,资源数据读取装置1000具体包括:
获取模块1100,用于获取待读取的资源的路径,其中,路径通过解析资源对应的标签值得到;
判断模块1200,用于在确定路径为远程路径后,判断资源对应的文件是否存储在本地空间中,本地空间包括缓存空间和临时文件目录;
下载模块1300,用于若资源对应的文件未存储在本地空间中,则根据远程路径,将资源对应的文件下载到临时文件目录中;
读取模块1400,用于将临时文件目录中资源对应的文件读取到内存中。
可选的,资源数据读取装置1000还包括第一读取模块,第一读取模块用于在判断资源对应的文件是否存储在本地空间中之前,具体用于:
读取缓存空间中缓存列表文件的内容,得到缓存列表;将缓存列表初始化到内存中。
可选的,判断资源对应的文件是否存储在本地空间中,包括:
判断资源对应的文件是否存储在缓存空间中或临时文件目录中;其中,判断资源对应的文件是否存储在缓存空间中,包括:在内存中查询缓存列表中缓存文件的标识字段;若查询到资源对应的文件的标识,则确定资源对应的文件存储在缓存空间中。
可选的,资源数据读取装置1000还包括生成模块,生成模块用于在根据远程路径,将资源对应 的文件下载到临时文件目录中之后,具体用于:
生成与下载到临时文件目录中的文件对应的缓存任务;将缓存任务添加到缓存队列中,缓存队列为在内存中创建的队列。
可选的,生成模块中缓存队列中包括一个或多个缓存任务,生成模块还用于将缓存任务添加到缓存队列中之后,具体用于:
获取内存中缓存队列中的缓存任务;将缓存任务对应的文件从临时文件目录中复制到缓存空间中。
可选的,资源数据读取装置1000还包括更新模块,更新模块用于在缓存任务对应的文件从临时文件目录中成功复制到缓存空间后,具体用于:
将缓存空间中与缓存任务对应的缓存文件的标识记录到内存中缓存列表的缓存文件的标识字段,得到更新后的缓存列表;将更新后的缓存列表写入缓存列表文件中。
图10所示实施例的资源数据读取装置可用于执行上述方法实施例的技术方案,其实现原理和技术效果类似,此处不再赘述。
图11为本公开实施例提供的一种电子设备的结构示意图。该电子设备可以是如上的服务器或终端。本公开实施例提供的电子设备可以执行上述实施例提供的资源数据加载的处理流程,或者上述实施例提供的资源数据读取的处理流程,如图11所示,电子设备1110包括:处理器1120、通讯接口1130和存储器1140;其中,计算机程序存储在存储器1140中,并被配置为由处理器1120执行如上述的资源数据加载方法,或者资源数据读取方法。
另外,本公开实施例还提供一种计算机可读存储介质,其上存储有计算机程序,计算机程序被处理器执行以实现上述实施例的资源数据加载方法,或者资源数据读取方法。
此外,本公开实施例还提供了一种计算机程序产品,该计算机程序产品包括计算机程序或指令,该计算机程序或指令被处理器执行时实现如上述的资源数据加载方法,或者资源数据读取方法。其中,计算机程序产品可以以一种或多种程序设计语言的任意组合来编写用于执行本公开实施例操作的程序代码,程序设计语言包括面向对象的程序设计语言,诸如Java、C++等,还包括常规的过程式程序设计语言,诸如“C”语言或类似的程序设计语言。程序代码可以完全地在用户计算设备上执行、部分地在用户设备上执行、作为一个独立的软件包执行、部分在用户计算设备上部分在远程计算设备上执行、或者完全在远程计算设备或服务器上执行。
需要说明的是,在本文中,术语“包括”、“包含”或者其任何其他变体意在涵盖非排他性的包含,从而使得包括一系列要素的过程、方法、物品或者装置不仅包括那些要素,而且还包括没有明确 列出的其他要素,或者是还包括为这种过程、方法、物品或者装置所固有的要素。在没有更多限制的情况下,由语句“包括……”限定的要素,并不排除在包括该要素的过程、方法、物品或者装置中还存在另外的相同要素。
本领域的技术人员能够理解,尽管在此所述的一些实施例包括其它实施例中所包括的某些特征而不是其它特征,但是不同实施例的特征的组合意味着处于本公开的范围之内并且形成不同的实施例。
本领域的技术人员能够理解,对各个实施例的描述都各有侧重,某个实施例中没有详述的部分,可以参见其他实施例的相关描述。
虽然结合附图描述了本公开的实施方式,但是本领域技术人员可以在不脱离本公开的精神和范围的情况下做出各种修改和变型,这样的修改和变型均落入由所附权利要求所限定的范围之内。

Claims (17)

  1. 一种资源数据读取方法,预先在缓存空间中创建缓存列表文件,所述缓存列表文件中存储缓存列表,所述缓存列表包括缓存文件的标识字段,所述缓存文件为缓存在所述缓存空间中的文件,所述方法包括:
    获取待读取的资源的路径,其中,所述路径通过解析所述资源对应的标签值得到;
    在确定所述路径为远程路径后,判断所述资源对应的文件是否存储在本地空间中,所述本地空间包括所述缓存空间和临时文件目录;
    若所述资源对应的文件未存储在本地空间中,则根据所述远程路径,将所述资源对应的文件下载到所述临时文件目录中;
    将所述临时文件目录中所述资源对应的文件读取到内存中。
  2. 根据权利要求1所述的方法,其中,所述在判断所述资源对应的文件是否存储在本地空间中之前,所述方法还包括:
    读取所述缓存空间中缓存列表文件的内容,得到缓存列表;
    将所述缓存列表初始化到内存中。
  3. 根据权利要求2所述的方法,其中,所述判断所述资源对应的文件是否存储在本地空间中,包括:
    判断所述资源对应的文件是否存储在所述缓存空间中或所述临时文件目录中;
    其中,所述判断所述资源对应的文件是否存储在所述缓存空间中,包括:在所述内存中查询所述缓存列表中缓存文件的标识字段;若查询到所述资源对应的文件的标识,则确定所述资源对应的文件存储在所述缓存空间中。
  4. 根据权利要求1所述的方法,其中,在所述根据所述远程路径,将所述资源对应的文件下载到所述临时文件目录中之后,所述方法还包括:
    生成与下载到所述临时文件目录中的文件对应的缓存任务;
    将所述缓存任务添加到缓存队列中,所述缓存队列为在内存中创建的队列。
  5. 根据权利要求4所述的方法,其中,所述缓存队列中包括一个或多个缓存任务,所述将所述缓存任务添加到缓存队列中之后,所述方法还包括:
    获取内存中所述缓存队列中的缓存任务;
    将所述缓存任务对应的文件从所述临时文件目录中复制到所述缓存空间中。
  6. 根据权利要求5所述的方法,其中,在所述缓存任务对应的文件从所述临时文件目录中成功复制到所述缓存空间后,所述方法还包括:
    将所述缓存空间中与所述缓存任务对应的缓存文件的标识记录到内存中所述缓存列表的缓存文件的标识字段,得到更新后的缓存列表;
    将所述更新后的缓存列表写入所述缓存列表文件中。
  7. 一种资源数据加载方法,包括:
    获取待处理的资源的标签值;
    根据所述标签值,采用权利要求1至6中任一项所述方法读取所述资源对应的文件到内存中;
    根据所述资源对应的文件,得到依赖资源列表;
    加载所述依赖资源列表中的依赖资源,并进行初始化,得到加载后的资源数据。
  8. 一种资源数据读取装置,预先在缓存空间中创建缓存列表文件,所述缓存列表文件中存储缓存列表,所述缓存列表包括缓存文件的标识字段,所述缓存文件为缓存在所述缓存空间中的文件,所述方法包括:
    获取模块,用于获取待读取的资源的路径,其中,所述路径通过解析所述资源对应的标签值得到;
    判断模块,用于在确定所述路径为远程路径后,判断所述资源对应的文件是否存储在本地空间中,所述本地空间包括所述缓存空间和临时文件目录;
    下载模块,用于若所述资源对应的文件未存储在本地空间中,则根据所述远程路径,将所述资源对应的文件下载到所述临时文件目录中;
    读取模块,用于将所述临时文件目录中所述资源对应的文件读取到内存中。
  9. 一种资源数据加载装置,包括:
    第一获取模块,用于获取待处理的资源的标签值;
    第一读取模块,用于根据所述标签值,采用权利要求8所述的资源数据读取装置读取所述资源对应的文件到内存中;
    依赖模块,用于根据所述资源对应的文件,得到依赖资源列表;
    加载模块,用于加载所述依赖资源列表中的依赖资源,并进行初始化,得到加载后的资源数据。
  10. 一种电子设备,包括:
    处理器;以及
    存储器,用于存储可在所述处理器上运行的计算机程序,
    所述处理器执行所述计算机程序时被配置为:
    获取待读取的资源的路径,其中,所述路径通过解析所述资源对应的标签值得到;
    在确定所述路径为远程路径后,判断所述资源对应的文件是否存储在本地空间中,所述本地空间包括所述缓存空间和临时文件目录;
    若所述资源对应的文件未存储在本地空间中,则根据所述远程路径,将所述资源对应的文件下载 到所述临时文件目录中;
    将所述临时文件目录中所述资源对应的文件读取到内存中。
  11. 根据权利要求10所述的电子设备,其中,所述处理器配置为:
    读取所述缓存空间中缓存列表文件的内容,得到缓存列表;
    将所述缓存列表初始化到内存中。
  12. 根据权利要求11所述的电子设备,其中,所述处理器还配置为:
    判断所述资源对应的文件是否存储在所述缓存空间中或所述临时文件目录中;
    其中,所述判断所述资源对应的文件是否存储在所述缓存空间中,包括:在所述内存中查询所述缓存列表中缓存文件的标识字段;若查询到所述资源对应的文件的标识,则确定所述资源对应的文件存储在所述缓存空间中。
  13. 根据权利要求10所述的电子设备,其中,所述处理器配置为:
    生成与下载到所述临时文件目录中的文件对应的缓存任务;
    将所述缓存任务添加到缓存队列中,所述缓存队列为在内存中创建的队列。
  14. 根据权利要求13所述的电子设备,其中,所述处理器还配置为:
    获取内存中所述缓存队列中的缓存任务;
    将所述缓存任务对应的文件从所述临时文件目录中复制到所述缓存空间中。
  15. 根据权利要求14所述的电子设备,其中,所述处理器还配置为:
    将所述缓存空间中与所述缓存任务对应的缓存文件的标识记录到内存中所述缓存列表的缓存文件的标识字段,得到更新后的缓存列表;
    将所述更新后的缓存列表写入所述缓存列表文件中。
  16. 一种电子设备,包括:
    处理器;以及
    存储器,用于存储可在所述处理器上运行的计算机程序,
    所述处理器执行所述计算机程序时实现如权利要求7所述的资源数据加载方法。
  17. 一种计算机可读存储介质,其上存储有计算机程序,所述计算机程序被处理器执行时实现如权利要求1至6中任一项所述的资源数据读取方法,或者如权利要求7所述的资源数据加载方法。
PCT/CN2021/115427 2021-07-02 2021-08-30 一种资源数据读取方法、装置、电子设备和存储介质 WO2023272919A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202110750353.3A CN113377722A (zh) 2021-07-02 2021-07-02 一种资源数据读取方法、装置和存储介质
CN202110750353.3 2021-07-02

Publications (1)

Publication Number Publication Date
WO2023272919A1 true WO2023272919A1 (zh) 2023-01-05

Family

ID=77580677

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2021/115427 WO2023272919A1 (zh) 2021-07-02 2021-08-30 一种资源数据读取方法、装置、电子设备和存储介质

Country Status (2)

Country Link
CN (1) CN113377722A (zh)
WO (1) WO2023272919A1 (zh)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113608800A (zh) * 2021-08-31 2021-11-05 北京字节跳动网络技术有限公司 项目启动方法、装置、电子设备及存储介质
CN117632885A (zh) * 2024-01-25 2024-03-01 太平金融科技服务(上海)有限公司 一种回溯系统中的资源同步方法、装置、设备及介质

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114936387B (zh) * 2022-07-25 2022-11-29 深圳市明源云科技有限公司 文本文件读取方法、写入方法、电子设备及可读存储介质

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104735112A (zh) * 2013-12-23 2015-06-24 阿里巴巴集团控股有限公司 发送资源文件的方法、缓存资源文件的方法和装置
US20170168936A1 (en) * 2015-12-11 2017-06-15 Netapp, Inc. Server-based persistence management in user space
CN108600382A (zh) * 2018-04-28 2018-09-28 广州联欣信息科技有限公司 一种在网络离线时app内容缓存的方法和计算机可读存储介质

Family Cites Families (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101710327A (zh) * 2009-12-04 2010-05-19 深圳创维数字技术股份有限公司 一种嵌入式浏览器本地临时文件的缓存方法
CN102035881B (zh) * 2010-11-19 2013-01-16 清华大学 一种云端存储系统的数据缓存方法
US9747300B2 (en) * 2011-06-15 2017-08-29 Amazon Technologies, Inc. Local networked storage linked to remote networked storage system
CN102750174B (zh) * 2012-06-29 2016-01-27 Tcl集团股份有限公司 文件加载方法及装置
CN102970358B (zh) * 2012-11-08 2016-06-15 百度在线网络技术(北京)有限公司 网盘中移动客户端的本地缓存的控制方法和装置
CN106372109A (zh) * 2016-08-19 2017-02-01 中国银联股份有限公司 互联网资源文件缓存方法及装置
CN109815425A (zh) * 2018-12-14 2019-05-28 平安科技(深圳)有限公司 缓存数据处理方法、装置、计算机设备和存储介质

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104735112A (zh) * 2013-12-23 2015-06-24 阿里巴巴集团控股有限公司 发送资源文件的方法、缓存资源文件的方法和装置
US20170168936A1 (en) * 2015-12-11 2017-06-15 Netapp, Inc. Server-based persistence management in user space
CN108600382A (zh) * 2018-04-28 2018-09-28 广州联欣信息科技有限公司 一种在网络离线时app内容缓存的方法和计算机可读存储介质

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113608800A (zh) * 2021-08-31 2021-11-05 北京字节跳动网络技术有限公司 项目启动方法、装置、电子设备及存储介质
CN117632885A (zh) * 2024-01-25 2024-03-01 太平金融科技服务(上海)有限公司 一种回溯系统中的资源同步方法、装置、设备及介质
CN117632885B (zh) * 2024-01-25 2024-04-16 太平金融科技服务(上海)有限公司 一种回溯系统中的资源同步方法、装置、设备及介质

Also Published As

Publication number Publication date
CN113377722A (zh) 2021-09-10

Similar Documents

Publication Publication Date Title
WO2023272919A1 (zh) 一种资源数据读取方法、装置、电子设备和存储介质
US11799984B2 (en) Installable web applications
US10242023B2 (en) Programming model for synchronizing browser caches across devices and web services
WO2016192556A1 (zh) 接口调用方法、装置及终端
US8572033B2 (en) Computing environment configuration
JP5869661B2 (ja) ネットワークストレージシステムにリンクされるローカルストレージ
US20140208326A1 (en) File presenting method and apparatus for a smart terminal
CN109074278B (zh) 验证移动应用中的有状态动态链接
WO2022083316A1 (zh) 一种应用运行的方法、装置及计算机存储介质
US11016785B2 (en) Method and system for mirror image package preparation and application operation
JP4376181B2 (ja) プログラム実行処理端末装置
US10166467B2 (en) Information processing device, data structure of game data, and recording medium
US20150126288A1 (en) Information processing device, program, and recording medium
WO2020206691A1 (zh) 应用程序的处理方法、装置、存储介质及电子设备
US10908948B2 (en) Multiple application instances in operating systems that utilize a single process for application execution
CN106257418B (zh) 用于通过使用辅助应用来评价应用的技术
WO2023216491A1 (zh) 动画资源的信息处理方法及装置、设备、介质及产品
WO2019161620A1 (zh) 应用依赖关系更新方法、终端、设备及存储介质
US8850355B2 (en) Systems and methods for communicating with media modules
US8196153B1 (en) Method and apparatus for associating device drivers via a device tree
CN109032693B (zh) 一种加载展示信息方法、装置、电子设备及可读存储介质
US10052555B2 (en) Information processing device, data structure of game data, and recording medium
WO2023193528A1 (zh) 文件解压方法、装置、电子设备及计算机可读存储介质
WO2023272918A1 (zh) 一种缓存空间管理方法、装置、电子设备和存储介质
WO2023272920A1 (zh) 一种缓存文件管理方法、装置、电子设备和存储介质

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 21947856

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE