WO2014161261A1 - 数据的存储方法及装置 - Google Patents

数据的存储方法及装置 Download PDF

Info

Publication number
WO2014161261A1
WO2014161261A1 PCT/CN2013/082003 CN2013082003W WO2014161261A1 WO 2014161261 A1 WO2014161261 A1 WO 2014161261A1 CN 2013082003 W CN2013082003 W CN 2013082003W WO 2014161261 A1 WO2014161261 A1 WO 2014161261A1
Authority
WO
WIPO (PCT)
Prior art keywords
type
network data
cache
data
cache entity
Prior art date
Application number
PCT/CN2013/082003
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 中兴通讯股份有限公司
Priority to EP13881423.1A priority Critical patent/EP3026573A4/en
Priority to US14/907,199 priority patent/US20160191652A1/en
Publication of WO2014161261A1 publication Critical patent/WO2014161261A1/zh

Links

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/50Network services
    • H04L67/56Provisioning of proxy services
    • H04L67/568Storing data temporarily at an intermediate stage, e.g. caching
    • H04L67/5682Policies or rules for updating, deleting or replacing the stored data
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/90Details of database functions independent of the retrieved data types
    • G06F16/95Retrieval from the web
    • G06F16/957Browsing optimisation, e.g. caching or content distillation
    • G06F16/9574Browsing optimisation, e.g. caching or content distillation of access to content, e.g. by caching
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/90Details of database functions independent of the retrieved data types
    • G06F16/903Querying
    • G06F16/90335Query processing
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/50Network services
    • H04L67/56Provisioning of proxy services
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Definitions

  • the present invention relates to the field of communications, and in particular to a method and an apparatus for storing data.
  • flexible caching can not only greatly reduce the pressure on the server, but also facilitate the users because of a faster user experience, for large applications and small applications.
  • Mobile terminal applications are usually classified in small applications. Most of them (about 99%) do not need real-time updates, and they are plagued by snail-like mobile internet speeds.
  • the data interaction with the server can be less or less. The user experience is even better.
  • Using caching can greatly ease the pressure of data interaction.
  • the usual applicable environments for cache management can include:
  • the database method is to store the relevant information of the file, such as: uniform resource locator (URL), path, download time, expiration time, etc., to the database after downloading the data file, and the next time you need to download, you can first Query in the database, if the current time has not expired, you can read the local file according to the path, so as to achieve the effect of the cache.
  • the file rule is to use the File.lastModifiedG method to get the last modification time of the file, and then compare it with the current time to judge whether it expires, and then achieve the effect of the cache.
  • the present invention provides a method and apparatus for storing data to at least solve the problem that the data caching solution provided in the related art relies excessively on remote network services, and at the same time, consumes a large amount of network traffic and power of the mobile terminal. According to an aspect of the invention, a method of storing data is provided.
  • the method for storing data includes: initiating a request message to a network side device, and acquiring network data to be cached; selecting one or more cache entity objects for the network data from the set of cached entity objects, and directly acquiring the obtained One type of network data is stored in one or more cache entity objects, or the serialized second type of network data is stored in one or more cache entity objects.
  • the method before storing the first type of network data in the one or more cache entity objects, the method further includes: obtaining a size of the first type of network data; determining whether the size of the first type of network data is less than or equal to the first The size of the remaining storage space in the cached entity object, wherein the first cache entity object has the highest storage priority level in one or more cache entity objects; if not, the first cache entity object is currently in accordance with a preset rule Part or all of the stored data is deleted, or part or all of the data stored in the first cache entity object is transferred to another cache entity object other than the first cache entity object, wherein the preset rule includes one of the following : Least Recently Used (LRU) rules, the time stored in the cached entity object.
  • LRU Least Recently Used
  • the method before storing the second type of network data in the one or more cache entity objects, the method further includes: obtaining a size of the second type of network data; determining whether the size of the second type of network data is less than or equal to the first The size of the remaining storage space in the cached entity object; if not, deleting some or all of the data currently stored in the first cached entity object according to a preset rule, or storing the portion stored in the first cached entity object or All data is transferred to other cache entity objects except the first cache entity object, wherein the preset rule includes one of the following: an LRU rule, a time stored in the cache entity object.
  • the method before storing the first type of network data into one or more cache entity objects, or storing the second type of network data into one or more cache entity objects, the method further includes: Network data or a second type of network data setting storage identifier, wherein the storage identifier is used in the first type
  • the network data or the second type of network data is stored in one or more cache entity objects to find the first type of network data or the second type of network data.
  • storing the first type of network data into one or more cache entity objects, or storing the second type of network data into one or more cache entity objects comprises: determining one or more cache entity objects Whether the storage identifier already exists in the medium; if yes, directly adopting the first type of network data or the second type of network data to overwrite the data corresponding to the storage identifier currently stored in one or more cache entity objects, or After the callback processing is performed on the data corresponding to the storage identifier, the data corresponding to the storage identifier is overwritten by using the first type of network data or the second type of network data.
  • setting the storage identifier for the first type of network data or the second type of network data comprises: traversing all the storage identifiers already existing in one or more cache entity objects; determining the first type of network data according to the traversal result or The storage identifier of the second type of network data setting, wherein the set storage identifier is different from all existing storage identifiers.
  • the set of cached entity objects comprises at least one of: an initially configured memory cache entity object; an initially configured file cache entity object; an initially configured database cache entity object; and a user-defined extended cache entity object.
  • a storage device for data is provided.
  • the storage device of the data includes: a first obtaining module, configured to initiate a request message to the network side device to obtain network data to be cached; and a storage module configured to select one or more network data from the set of cached entity objects Caching entity objects, and directly storing the obtained first type of network data into one or more cache entity objects, or storing the serialized second type of network data to one or more caches In the entity object.
  • the device further includes: a second obtaining module, configured to acquire a size of the first type of network data; and a first determining module, configured to determine whether the size of the first type of network data is less than or equal to the first cache entity object The size of the remaining storage space, wherein the first cache entity object has the highest storage priority level in the one or more cache entity objects; the first processing module is configured to: when the output of the first determination module is negative, according to the preset The rule deletes part or all of the data currently stored in the first cache entity object, or transfers part or all of the data stored in the first cache entity object to other cache entity objects except the first cache entity object.
  • the preset rule includes one of the following: an LRU rule, a time stored in a cache entity object.
  • the device further includes: a third obtaining module, configured to acquire a size of the second type of network data; and a second determining module, configured to determine whether the size of the second type of network data is less than or equal to the first cache entity object
  • the size of the remaining storage space in the second processing module is set to delete part or all of the data currently stored in the first cache entity object according to a preset rule when the output of the second determining module is negative, or Some or all of the data stored in a cached entity object is transferred to other cached entity objects than the first cached entity object, wherein the preset rule includes one of the following: an LRU rule, a time stored in the cached entity object.
  • the apparatus further includes: a setting module, configured to set a storage identifier for the first type of network data or the second type of network data, wherein the storage identifier is used to be the first type of network data or the second type
  • the network data is stored in one or more cache entity objects to find the first type of network data or the second type of network data.
  • the storage module includes: a determining unit, configured to determine whether a storage identifier already exists in one or more cache entity objects; and the processing unit is configured to directly adopt the first type of network data when the output of the determining unit is YES or The second type of network data is used to cover data corresponding to the storage identifier currently stored in one or more cache entity objects, or after the callback processing is performed on the data corresponding to the storage identifier, and then adopting the first type of network data. Or the second type of network data overwrites the data corresponding to the storage identifier.
  • the setting module comprises: a traversing unit, configured to traverse all storage identifiers already existing in one or more cache entity objects; and a determining unit configured to determine the first type of network data or the second type of network according to the traversal result The storage identifier of the data setting, where the set storage identifier is different from all existing storage identifiers.
  • the request message is sent to the network side device to obtain the network data to be cached; one or more cache entity objects are selected from the set of cached entity objects for the network data, and the obtained first type of network data is directly obtained.
  • the different types of network data received by the device reduce the request for repeatedly acquiring the same network data to the network side device, and reduce the frequency of information interaction with the network side device, thereby solving the problem that the data caching solution provided in the related art is excessively Relying on remote network services, it also requires a large amount of network traffic and the problem of mobile terminal power, which can reduce the dependence on the network and save network traffic and mobile terminal power.
  • FIG. 2 is a schematic diagram of android platform cache management according to a preferred embodiment of the present invention
  • FIG. 3 is a storage device of data according to an embodiment of the present invention.
  • FIG. 4 is a block diagram showing the structure of a data storage device in accordance with a preferred embodiment of the present invention.
  • Step S102 Initiating a request message to a network side device to obtain network data to be cached
  • Step S104 Select one or more caches for network data from the set of cached entity objects An entity object, and directly storing the obtained first type of network data into one or more cache entity objects, or storing the serialized second type of network data to one or more cache entity objects in.
  • the data caching solution provided in the related art relies excessively on remote network services, and also consumes a large amount of network traffic and mobile terminal power.
  • the method shown in FIG. 1 is used to initiate a request message to the network side device to obtain network data to be cached (for example, image data and string data); and select one or more cache entities for the network data from the set of cached entity objects.
  • the network data stored in the selected one or more cache entity objects may be divided into two types - a first type, a basic data type, and a data type that has been serialized by itself, for example: int, float , string data; this type of network data does not need to be serialized, but can be directly stored; second type, structure type or picture type; this type of network data can only be stored after serialization.
  • the foregoing set of cache entity objects may include, but is not limited to, at least one of the following:
  • the cache entity object set implements a backup/cache component, and a framework is constructed to uniformly perform storage of different types of network data.
  • the initial configuration based on the cache abstract class has implemented the file as a storage carrier data.
  • the cache, the data cache with memory as the storage carrier, and the data cache with the database as the storage carrier cache three basic cache categories.
  • the user can also implement the abstract class interface according to his own needs to define his own cache implementation or continue to extend the above-mentioned three implementations.
  • FIG. 2 is a schematic diagram of android platform cache management in accordance with a preferred embodiment of the present invention. As shown in Figure 2, the android platform cache management is as follows:
  • Cache management class supports generic data and can eliminate data according to LRU principle.
  • the cache management class can provide the following functions - function one, clear all data of the current type cache; Function 2, according to ⁇ get the V value in all data of the current type cache, where ⁇ is the data type of the key, android platform Java syntax supports generic declaration; V is the value of the data type, android platform Java syntax supports the generic declaration Function 3, storing the corresponding (KV) data in the cache; function four, removing the corresponding (KV) data from the cache; function five, obtaining the size of the cache; function six, obtaining the maximum limit of the cache; in the preferred embodiment
  • support for generic key-values can be set according to the actual situation.
  • the file cache and database cache implemented by this cache management component are both ⁇ String, Extemalizabl type, and any file or data that can be serialized can be cached.
  • the Cache entity interface support generic data, and implement data access.
  • the abstract class of the cached entity provides the following types of interfaces - the first type of interface, the longest unaccessed (KV) data in the cache, to be deleted when the cache is about to overflow; the second type of interface, in the cache according to the KEY The corresponding type of VALUE is obtained.
  • the third type of interface stores data into the cache according to the KEY. When the data corresponding to the KEY already exists in the cache, the corresponding V value is returned.
  • the fourth type of interface is deleted according to the KEY.
  • Memory cache class which supports generic data and implements access of data objects in memory.
  • the file cache class only supports ⁇ String, E X temali Z able> type data, and realizes that the data object is accessed by file.
  • the database cache class only supports ⁇ String, E X temali Z able> type data, and realizes data object access by database.
  • Step S1 acquiring the size of the first type of network data
  • Step S2 determining the first Whether the size of a type of network data is less than or equal to the size of the remaining storage space in the first cache entity object, wherein the first cache entity object has the highest storage priority level in one or more cache entity objects
  • Step S3 No, the part or all of the data currently stored in the first cache entity object is deleted according to a preset rule, or part or all of the data stored in the first cache entity object is transferred to the object other than the first cache entity object.
  • the foregoing preset rules may include, but are not limited to, one of the following: an LRU rule, a time stored in a cache entity object.
  • network data e.g., character string data
  • the cache entity object here may be a memory cache entity object, a file cache entity object or a database cache entity object that has been configured, or may be a user-defined extended cache entity object.
  • the storage policy may be preset (for example, the priority of the cached entity object).
  • the memory cache entity object may be set to have the highest priority, and the file cache entity object may be set.
  • the priority of the database cache entity object is second to last. Then, it starts to determine whether the current storage capacity of the highest priority memory cache entity object satisfies the network data just received, and if so, directly stores the received network data into the memory cache entity object. If the current storage capacity of the memory cache entity object cannot accommodate the network data just received, at this time, the aging data that has not been used recently may be used according to a preset rule (for example, aging the unused aging data in the memory cache entity object).
  • the file cache entity object or the database cache entity object is stored in the file cache entity object, and the network data just received is stored in the memory cache entity object, so that the data cache processing can be flexibly performed so as not to affect the performance and experience of the application.
  • excessive use of the memory cache entity object is avoided, so even if the current storage capacity of the memory cache entity object can accommodate the network data just received, after the network data is stored, the memory cache
  • the usage of entity objects has been After exceeding the preset ratio (for example: 80%), you need to store the recently unused aging data into the file cache entity object according to the preset rules (for example: phasing out the recently unused aging data in the memory cache entity object).
  • the database is cached in an entity object. After the above cache processing, if the same string data needs to be displayed after accessing the web page next time, there is no need to initiate a request for data interaction to the network, but the corresponding string can be obtained directly from the memory cache entity object. Data is displayed to reduce network traffic, speed up page display, and enhance the user experience.
  • the method may further include the following steps: Step S4: acquiring the size of the second type of network data; Step S5: determining the first Whether the size of the network data of the second type is less than or equal to the size of the remaining storage space in the first cache entity object; Step S6: If not, performing part or all of the data currently stored in the first cache entity object according to a preset rule Deleting, or transferring some or all of the data stored in the first cache entity object to other cache entity objects except the first cache entity object, where the preset rules may include but are not limited to one of the following: The minimum time to use LRU rules, stored in cached entity objects.
  • network data for example, picture data
  • serialization processing of the data type needs to be implemented. This can be stored as a VALUE value.
  • the cache entity object here may be a memory cache entity object, a file cache entity object or a database cache entity object that has been configured, or may be a user-defined extended cache entity object.
  • the storage policy may be preset (for example, the priority of the cached entity object).
  • the memory cache entity object may be set to have the highest priority, and the file cache entity object may be set.
  • the priority of the database cache entity object is second to last. Then, it starts to determine whether the current storage capacity of the highest priority memory cache entity object satisfies the network data just received, and if so, directly stores the received network data into the memory cache entity object. If the current storage capacity of the memory cache entity object cannot accommodate the network data just received, at this time, the aging data that has not been used recently may be used according to a preset rule (for example, aging the unused aging data in the memory cache entity object).
  • step S104 storing the first type of network data into one or more cache entity objects, or before storing the second type of network data into one or more cache entity objects, may further include the following Processing: Step S7: setting a storage identifier for the first type of network data or the second type of network data, where the storage identifier is used to store the first type of network data or the second type of network data to one or more The cached entity object is then searched for the first type of network data or the second type of network data.
  • the storage identifier KEY may be set for each received network data, and the network data is used as VALUE to establish a correspondence between KEY and VALUE, and stored in one or more cache entity objects.
  • storing the first type of network data into one or more cache entity objects, or storing the second type of network data into one or more cache entity objects may include the following operations - Step S8: determining whether the storage identifier already exists in one or more cache entity objects; Step S9: if yes, directly adopting the first type of network data or the second type of network data pair in one or more cache entity objects The currently stored data corresponding to the storage identifier is overwritten, or after the callback processing is performed on the data corresponding to the storage identifier, the data corresponding to the storage identifier is covered by using the first type of network data or the second type of network data. .
  • the string data if the string data does not need to be serialized, it is directly stored as a VALUE value; if the image data needs to be serialized by the data type, Can be stored as a VALUE value.
  • the network data is distinguished by the storage identifier KEY.
  • the storage identifier KEY allocated for the network data is not unique, that is, the cache entity object may already have the same identifier as the storage identifier KEY allocated for the network data just received. At this time, if there is data corresponding to the KEY in the cache entity object, the new data is directly overwritten by the old data in the stored procedure.
  • step S7 setting the storage identifier for the first type of network data or the second type of network data may include the following steps: Step S10: Traversing all storage identifiers that already exist in one or more cache entity objects; S11: Determine, according to the traversal result, a storage identifier set for the first type of network data or the second type of network data, where the set storage identifier is different from all existing storage identifiers.
  • the processing flow when using the android platform caching tool for caching may include the following processing steps: First, serializing the cache data type, implementing the Externalizable interface; Step 2, instantiating the cache management class , specify the cache policy, that is, memory, file or database, and optionally specify the maximum cache limit; the third step, specify the storage identifier KEY and serialized data, use the cache function corresponding to the cache management class; The judgment of the legality of the KEY and the VALUE must not be null; the fifth step, calculating the size of the data to be stored, and ensuring that it is less than or equal to the maximum limit of the cache; and the sixth step, determining whether the KEY in the cache already exists, if present The newly generated VALUE value will be overwritten with the original value for storage.
  • the aging data is determined as follows: In the in-memory cache mechanism, the LinkedHashMap can be stored in chronological order. Therefore, the top-ranked data is the aging data.
  • the database In the file caching mechanism, in addition to the KEY file name, the database also has the creation time of the corresponding file, so that it can be judged according to the time.
  • the database caching mechanism is similar to file caching. When the data is stored, a time field is stored, and the time field can be queried to know the aging data.
  • the seventh step is to write the KV value into the cache.
  • a LinkedHashMap is arranged according to the access order, and the data is added to add a mapping entry; the file caching mechanism can use the database to save the file cache related information.
  • the database cache mechanism is to add an entry to the database; the eighth step, if it is KEY already exists in the data cache, will return the KV old value through the callback; when using the above android platform cache tool to obtain data, if the KEY is known, you can directly use the get cache data function, find through the KEY value Corresponding data.
  • the data storage device may include: a first obtaining module 100, configured to initiate a request message to the network side device, to obtain network data to be cached; and the storage module 102 is configured to be from the cache entity object set.
  • the network data selects one or more cache entity objects, and directly stores the obtained first type of network data into one or more cache entity objects, or stores the serialized second type network data. To one or more cache entity objects.
  • the foregoing apparatus may further include: a second obtaining module 104, configured to acquire a size of the first type of network data; and a first determining module 106, configured to determine a size of the first type of network data.
  • the first processing module 108 is set to be at the first When the output of the determination module is negative, part or all of the data currently stored in the first cache entity object is deleted according to a preset rule, or part or all of the data stored in the first cache entity object is transferred to the In a cache entity object other than the cache entity object, the foregoing preset rule may include, but is not limited to, one of the following: an LRU rule, a time stored in the cache entity object.
  • an LRU rule a time stored in the cache entity object.
  • the foregoing apparatus may further include: a third obtaining module 110 configured to acquire a size of the second type of network data; and a second determining module 112 configured to determine a size of the second type of network data Whether it is less than or equal to the size of the remaining storage space in the first cache entity object; the second processing module 114 is configured to: when the second judgment module outputs no, the currently stored part of the first cache entity object according to a preset rule Or all data is deleted, or part or all of the data stored in the first cache entity object is transferred to other cache entity objects except the first cache entity object, wherein the preset rules may include but are not limited to the following One: LRU rules, the time stored in the cached entity object.
  • a third obtaining module 110 configured to acquire a size of the second type of network data
  • a second determining module 112 configured to determine a size of the second type of network data Whether it is less than or equal to the size of the remaining storage space in the first cache entity object
  • the second processing module 114 is configured to
  • the apparatus may further include: a setting module 116 configured to set a storage identifier for the first type of network data or the second type of network data, wherein the storage identifier is used to be the first type
  • the network data or the second type of network data is stored in one or more cache entity objects to find the first type of network data or the second type of network data.
  • the storage module 102 may include: a determining unit (not shown) configured to determine whether a storage identifier already exists in one or more cache entity objects; a processing unit (not shown) is set to determine When the unit output is YES, the data corresponding to the storage identifier currently stored in one or more cache entity objects is directly covered by the first type of network data or the second type of network data, or the pair is stored and identified. After the corresponding data is subjected to the callback processing, the data corresponding to the storage identifier is overwritten by using the first type of network data or the second type of network data.
  • the setting module 116 may include: a traversal unit (not shown) configured to traverse all storage identifiers already existing in one or more cache entity objects; a determining unit (not shown), configured to The traversal result is determined as a storage identifier set by the first type of network data or the second type of network data, wherein the set storage identifier is different from all existing storage identifiers.
  • the above embodiments achieve the following technical effects (it is necessary to explain that these effects are effects that can be achieved by some preferred embodiments): using the technical solution provided by the present invention, realizing locally
  • the network data cache when the local application frequently requests the network data and the demand for various resources, can greatly improve the processing performance of the mobile terminal by using the cache component, and can also reduce the request initiated by the network.
  • the invention constructs three basic cache categories of memory, file and database, and also reserves the extended use of other cache systems, supports cache of network graphics, unlimited backup content, and can back up arbitrary data and files. , pictures, etc. downloaded from the network.
  • modules or steps of the present invention can be implemented by a general-purpose computing device, which can be concentrated on a single computing device or distributed over a network composed of multiple computing devices. Alternatively, they may be implemented by program code executable by the computing device, such that they may be stored in the storage device by the computing device and, in some cases, may be different from the order herein.
  • the steps shown or described are performed, or they are separately fabricated into individual integrated circuit modules, or a plurality of modules or steps are fabricated as a single integrated circuit module.
  • the invention is not limited to any specific combination of hardware and software.
  • the above is only the preferred embodiment of the present invention, and is not intended to limit the present invention, and various modifications and changes can be made to the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and scope of the present invention are intended to be included within the scope of the present invention.

Landscapes

  • Engineering & Computer Science (AREA)
  • Databases & Information Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Data Mining & Analysis (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Computational Linguistics (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
  • Information Transfer Between Computers (AREA)

Abstract

本发明公开了一种数据的存储方法及装置,在上述方法中,向网络侧设备发起请求消息,获取待缓存的网络数据;从缓存实体对象集合中为网络数据选取一个或多个缓存实体对象,并直接将获取到的第一类型的网络数据存储至一个或多个缓存实体对象中,或者,将经过序列化处理后的第二类型的网络数据存储至一个或多个缓存实体对象中。根据本发明提供的技术方案,进而可以减少对网络的依赖,节省网络流量和移动终端的电量。

Description

数据的存储方法及装置
技术领域 本发明涉及通信领域, 具体而言, 涉及一种数据的存储方法及装置。 背景技术 相关技术中, 无论对于大型应用还是小型应用而言, 灵活的缓存可以说不仅大大 减轻了服务器的压力, 而且因为更快速的用户体验而方便了广大用户。 移动终端应用 通常归类于小型应用, 其中, 大部分 (99%左右) 的应用均不需要实时更新, 而且诟 病于蜗牛般的移动网速, 与服务器的数据交互当是能少则少, 这样用户体验才能更加 出色。 采用缓存可以大大缓解数据交互的压力。 缓存管理通常的适用环境可以包括:
( 1 ) 提供网络服务的应用;
(2) 数据无需实时更新, 即便是短短几分钟的延迟也可以采用缓存机制;
(3 )缓存的过期时间是可以接受的,其不会导致某些数据因为更新不及时而影响 产品的形象。 由此, 缓存所能带来的好处有如下几点:
( 1 ) 可以大大减小服务器的压力;
(2) 客户端的响应速度大大加快;
(3 ) 客户端数据加载出错的概率大大降低, 极大地提高了应用的稳定性;
(4) 在一定程度上可以支持离线浏览或者可以说为离线浏览提供了技术支持。 目前, 两种较为常用的缓存管理方法为: 数据库法和文件法。 数据库法是在下载 完数据文件后, 将文件的相关信息, 例如: 统一资源定位符(URL)、路径、下载时间、 过期时间等存放到数据库,在下次需要下载的时候,可以根据 URL先从数据库中查询, 如果查询到当前时间并未过期, 则可以根据路径读取本地文件, 从而实现缓存的效果。 文件法则是使用 File.lastModifiedG方法得到文件的最后修改时间, 然后与当前时间进 行比较从而判断是否过期, 进而实现缓存的效果。 然而, 相关技术中所提供的数据缓存解决方案过分地依赖远程网络服务, 同时还 需大量地耗费网络流量以及移动终端的电量。 发明内容 本发明提供了一种数据的存储方法及装置, 以至少解决相关技术中所提供的数据 缓存解决方案过分地依赖远程网络服务, 同时还需大量地耗费网络流量以及移动终端 电量的问题。 根据本发明的一个方面, 提供了一种数据的存储方法。 根据本发明的数据的存储方法包括: 向网络侧设备发起请求消息, 获取待缓存的 网络数据; 从缓存实体对象集合中为网络数据选取一个或多个缓存实体对象, 并直接 将获取到的第一类型的网络数据存储至一个或多个缓存实体对象中, 或者, 将经过序 列化处理后的第二类型的网络数据存储至一个或多个缓存实体对象中。 优选地, 在将第一类型的网络数据存储至一个或多个缓存实体对象中之前, 还包 括: 获取第一类型的网络数据的大小; 判断第一类型的网络数据的大小是否小于或等 于第一缓存实体对象中的剩余存储空间的大小, 其中, 第一缓存实体对象在一个或多 个缓存实体对象中的存储优先级别最高; 如果否, 则按照预设规则将第一缓存实体对 象中当前存储的部分或全部数据进行删除, 或者, 将第一缓存实体对象中存储的部分 或全部数据转移至除第一缓存实体对象之外的其他缓存实体对象中, 其中, 预设规则 包括以下之一: 最近最少使用 (LRU) 规则、 在缓存实体对象中存储的时间。 优选地, 在将第二类型的网络数据存储至一个或多个缓存实体对象中之前, 还包 括: 获取第二类型的网络数据的大小; 判断第二类型的网络数据的大小是否小于或等 于第一缓存实体对象中的剩余存储空间的大小; 如果否, 则按照预设规则将第一缓存 实体对象中当前存储的部分或全部数据进行删除, 或者, 将第一缓存实体对象中存储 的部分或全部数据转移至除第一缓存实体对象之外的其他缓存实体对象中, 其中, 预 设规则包括以下之一: LRU规则、 在缓存实体对象中存储的时间。 优选地, 在将第一类型的网络数据存储至一个或多个缓存实体对象中, 或者, 将 第二类型的网络数据存储至一个或多个缓存实体对象中之前, 还包括: 为第一类型的 网络数据或者第二类型的网络数据设置存储标识, 其中, 存储标识用于在将第一类型 的网络数据或者第二类型的网络数据存储至一个或多个缓存实体对象中之后查找第一 类型的网络数据或者第二类型的网络数据。 优选地, 将第一类型的网络数据存储至一个或多个缓存实体对象中, 或者, 将第 二类型的网络数据存储至一个或多个缓存实体对象中包括: 判断一个或多个缓存实体 对象中是否已经存在存储标识; 如果存在, 则直接采用第一类型的网络数据或者第二 类型的网络数据对在一个或多个缓存实体对象中当前存储的与存储标识对应的数据进 行覆盖, 或者在对与存储标识对应的数据进行回调处理后, 再采用第一类型的网络数 据或者第二类型的网络数据对与存储标识对应的数据进行覆盖。 优选地, 为第一类型的网络数据或者第二类型的网络数据设置存储标识包括: 遍 历一个或多个缓存实体对象中已经存在的全部存储标识; 根据遍历结果确定为第一类 型的网络数据或者第二类型的网络数据设置的存储标识, 其中, 设置的存储标识与已 经存在的全部存储标识均不相同。 优选地, 缓存实体对象集合包括以下至少之一: 初始配置的内存缓存实体对象; 初始配置的文件缓存实体对象; 初始配置的数据库缓存实体对象; 用户自定义的扩展 缓存实体对象。 根据本发明的另一方面, 提供了一种数据的存储装置。 根据本发明的数据的存储装置包括: 第一获取模块, 设置为向网络侧设备发起请 求消息, 获取待缓存的网络数据; 存储模块, 设置为从缓存实体对象集合中为网络数 据选取一个或多个缓存实体对象, 并直接将获取到的第一类型的网络数据存储至一个 或多个缓存实体对象中, 或者, 将经过序列化处理后的第二类型的网络数据存储至一 个或多个缓存实体对象中。 优选地, 上述装置还包括: 第二获取模块, 设置为获取第一类型的网络数据的大 小; 第一判断模块, 设置为判断第一类型的网络数据的大小是否小于或等于第一缓存 实体对象中的剩余存储空间的大小, 其中, 第一缓存实体对象在一个或多个缓存实体 对象中的存储优先级别最高; 第一处理模块, 设置为在第一判断模块输出为否时, 按 照预设规则将第一缓存实体对象中当前存储的部分或全部数据进行删除, 或者, 将第 一缓存实体对象中存储的部分或全部数据转移至除第一缓存实体对象之外的其他缓存 实体对象中, 其中, 预设规则包括以下之一: LRU规则、 在缓存实体对象中存储的时 间。 优选地, 上述装置还包括: 第三获取模块, 设置为获取第二类型的网络数据的大 小; 第二判断模块, 设置为判断第二类型的网络数据的大小是否小于或等于第一缓存 实体对象中的剩余存储空间的大小; 第二处理模块, 设置为在第二判断模块输出为否 时, 按照预设规则将第一缓存实体对象中当前存储的部分或全部数据进行删除, 或者, 将第一缓存实体对象中存储的部分或全部数据转移至除第一缓存实体对象之外的其他 缓存实体对象中, 其中, 预设规则包括以下之一: LRU规则、 在缓存实体对象中存储 的时间。 优选地, 上述装置还包括: 设置模块, 设置为为第一类型的网络数据或者第二类 型的网络数据设置存储标识, 其中, 存储标识用于在将第一类型的网络数据或者第二 类型的网络数据存储至一个或多个缓存实体对象中之后查找第一类型的网络数据或者 第二类型的网络数据。 优选地, 存储模块包括: 判断单元, 设置为判断一个或多个缓存实体对象中是否 已经存在存储标识; 处理单元, 设置为在判断单元输出为是时, 则直接采用第一类型 的网络数据或者第二类型的网络数据对在一个或多个缓存实体对象中当前存储的与存 储标识对应的数据进行覆盖, 或者在对与存储标识对应的数据进行回调处理后, 再采 用第一类型的网络数据或者第二类型的网络数据对与存储标识对应的数据进行覆盖。 优选地, 设置模块包括: 遍历单元, 设置为遍历一个或多个缓存实体对象中已经 存在的全部存储标识; 确定单元, 设置为根据遍历结果确定为第一类型的网络数据或 者第二类型的网络数据设置的存储标识, 其中, 设置的存储标识与已经存在的全部存 储标识均不相同。 通过本发明, 采用向网络侧设备发起请求消息, 获取待缓存的网络数据; 从缓存 实体对象集合中为网络数据选取一个或多个缓存实体对象, 并直接将获取到的第一类 型的网络数据存储至一个或多个缓存实体对象中, 或者, 将经过序列化处理后的第二 类型的网络数据存储至一个或多个缓存实体对象中, 即通过构建的缓存实体对象集合 来存储从网络侧设备接收到的不同类型的网络数据, 减少向网络侧设备重复发起获取 相同网络数据的请求, 降低与网络侧设备的信息交互频率, 由此解决了相关技术中所 提供的数据缓存解决方案过分地依赖远程网络服务, 同时还需大量地耗费网络流量以 及移动终端电量的问题, 进而可以减少对网络的依赖, 节省网络流量和移动终端的电 附图说明 此处所说明的附图用来提供对本发明的进一步理解, 构成本申请的一部分, 本发 明的示意性实施例及其说明用于解释本发明, 并不构成对本发明的不当限定。 在附图 中- 图 1是根据本发明实施例的数据的存储方法; 图 2是根据本发明优选实施例的 android平台缓存管理的示意图; 图 3是根据本发明实施例的数据的存储装置的结构框图; 图 4是根据本发明优选实施例的数据的存储装置的结构框图。 具体实施方式 下文中将参考附图并结合实施例来详细说明本发明。 需要说明的是, 在不冲突的 情况下, 本申请中的实施例及实施例中的特征可以相互组合。 图 1是根据本发明实施例的数据的存储方法。 如图 1所示, 该方法可以包括以下 处理步骤: 步骤 S102: 向网络侧设备发起请求消息, 获取待缓存的网络数据; 步骤 S104: 从缓存实体对象集合中为网络数据选取一个或多个缓存实体对象, 并 直接将获取到的第一类型的网络数据存储至一个或多个缓存实体对象中, 或者, 将经 过序列化处理后的第二类型的网络数据存储至一个或多个缓存实体对象中。 相关技术中所提供的数据缓存解决方案过分地依赖远程网络服务, 同时还需大量 地耗费网络流量以及移动终端电量。 采用如图 1所示的方法, 向网络侧设备发起请求 消息, 获取待缓存的网络数据(例如: 图片数据、 字符串数据); 从缓存实体对象集合 中为网络数据选取一个或多个缓存实体对象, 并直接将获取到的第一类型的网络数据 存储至一个或多个缓存实体对象中, 或者, 将经过序列化处理后的第二类型的网络数 据存储至一个或多个缓存实体对象中, 即通过构建的缓存实体对象集合来存储从网络 侧设备接收到的不同类型的网络数据, 减少向网络侧设备重复发起获取相同网络数据 的请求, 降低与网络侧设备的信息交互频率, 由此解决了相关技术中所提供的数据缓 存解决方案过分地依赖远程网络服务, 同时还需大量地耗费网络流量以及移动终端电 量的问题, 进而可以减少对网络的依赖, 节省网络流量和移动终端的电量。 需要说明的是, 在上述选取的一个或多个缓存实体对象中存储的网络数据可以分 为两种类型- 第一类型、 基本数据类型以及自身已经实现序列化的数据类型, 例如: int、 float, 字符串数据; 该类网络数据无需再经过序列化处理, 而可以直接进行存储; 第二类型、 结构体类型或者图片类型; 该类网络数据只有在经过序列化处理后, 才能够进行存储。 在优选实施过程中, 上述缓存实体对象集合可以包括但不限于以下至少之一:
( 1 ) 初始配置的内存缓存实体对象;
(2) 初始配置的文件缓存实体对象; ( 3 ) 初始配置的数据库缓存实体对象;
(4) 用户自定义的扩展缓存实体对象。 在优选实施例中, 上述缓存实体对象集合实现了一个备份 /缓存组件, 构建了一个 框架来统一执行不同类型网络数据的存储, 其初始配置基于缓存抽象类已经实现了以 文件为存储载体的数据缓存、 以内存为存储载体的数据缓存以及以数据库为存储载体 的数据缓存三种基本的缓存类别, 同时用户也可以根据自身需要实现抽象类接口定义 自己的缓存实现或者继续扩展已经实现的上述三种缓存方式, 以满足实际应用过程中 的多样性。 在上述两种功能的基础上, 用户还可以通过封装的缓存管理类对象来使用 缓存功能。 下面结合图 2以安卓 (android) 平台的缓存管理组件为例, 对 android平台缓存 管理的实现方法做进一步的详细描述。图 2是根据本发明优选实施例的 android平台缓 存管理的示意图。 如图 2所示, android平台缓存管理如下:
( 1 ) 缓存管理类, 支持泛型数据并可以按照 LRU原则对数据进行淘汰。 缓存管理类可以提供以下各项功能- 功能一、 清除当前类型缓存的所有数据; 功能二、 根据 κ得到当前类型缓存的所有数据中的 V值, 其中, Κ为键的数据类 型, android平台 Java语法支持泛型声明; V为值的数据类型, android平台 Java语法 支持泛型声明; 功能三、 存入缓存对应的 (K-V) 数据; 功能四、 从缓存中移除对应 (K-V) 数据; 功能五、 获取缓存的大小; 功能六、 获取缓存的最大限制; 在该优选实施例中, 缓存管理支持泛型键 -值, 可以根据实际情况进行设置。 本缓 存管理组件实现的文件缓存和数据库缓存都是 <String, Extemalizabl 类型, 任何可以 序列化的文件或者数据都可以进行缓存。
(2) 缓存实体接口, 支持泛型数据, 实现数据存取。 缓存实体的抽象类提供了以下几类接口- 第一类接口、 获取该缓存中的最久未被访问的 (K-V) 数据, 以便在缓存即将溢 出时删除; 第二类接口、 在缓存中根据 KEY得到对应的 VALUE; 第三类接口、 根据 KEY向缓存中存入数据, 当缓存中已存在与 KEY对应的数据 时, 返回已经存在的对应的 V值; 第四类接口、 根据 KEY删除缓存中对应的数据; 第五类接口、 获取缓存的最大限制值; 第六类接口、 获取已经缓存数据的大小 /数量; 第七类接口、 遍历得到 KEY的 SET对象。
(3 ) 内存缓存类, 支持泛型数据, 实现数据对象在内存中的存取。
(4)文件缓存类, 仅支持 <String, EXtemaliZable>型数据, 实现数据对象以文件方 式进行存取。 ( 5 )数据库缓存类, 仅支持 <String, EXtemaliZable>型数据, 实现数据对象以数据 库方式进行存取。
( 6) Externalizable, 可序列化的值对象数据类型, android平台下由 Extemalizable 接口完成该功能。 优选地, 在步骤 S104, 将第一类型的网络数据存储至一个或多个缓存实体对象中 之前, 还可以包括以下操作: 步骤 S1 : 获取第一类型的网络数据的大小; 步骤 S2:判断第一类型的网络数据的大小是否小于或等于第一缓存实体对象中的 剩余存储空间的大小, 其中, 第一缓存实体对象在一个或多个缓存实体对象中的存储 优先级别最高; 步骤 S3 : 如果否, 则按照预设规则将第一缓存实体对象中当前存储的部分或全部 数据进行删除, 或者, 将第一缓存实体对象中存储的部分或全部数据转移至除第一缓 存实体对象之外的其他缓存实体对象中, 其中, 上述预设规则可以包括但不限于以下 之一: LRU规则、 在缓存实体对象中存储的时间。 在优选实施例中, 当从网络侧设备接收到网络数据 (例如: 字符串数据) 时, 经 过判断发现此种类型的网络数据不需要进行序列化处理, 而可以直接作为 VALUE值 来进行存储。 其次, 需要从缓存实体对象集合中为网络数据选取一个或多个缓存实体 对象, 同时可以指定每个缓存实体对象的最大容量限制。 此处的缓存实体对象可以是 已经配置完成的内存缓存实体对象、 文件缓存实体对象或者数据库缓存实体对象, 当 然也可以是用户自定义的扩展缓存实体对象。 在对网络数据进行存储的过程中, 可以 预先设定存储策略(例如: 缓存实体对象的优先级), 在该优选实施例中, 可以设定内 存缓存实体对象的优先级最高、 文件缓存实体对象的优先级次之、 数据库缓存实体对 象的优先级排在最后。 然后, 开始判断优先级最高的内存缓存实体对象当前的存储容 量是否满足刚刚接收到的网络数据, 如果可以满足则直接将接收到的网络数据存储至 内存缓存实体对象中。 而如果内存缓存实体对象当前的存储容量无法容纳刚刚接收到 的网络数据, 此时, 可以根据预设规则 (例如: 淘汰内存缓存实体对象中近期未使用 的老化数据) 将近期未使用的老化数据存入文件缓存实体对象或者数据库缓存实体对 象中, 而将刚接收到的网络数据存入内存缓存实体对象, 从而能够灵活地进行数据缓 存处理, 以便不影响应用的性能和体验。 当然, 为了不影响终端侧设备的处理能力, 避免过度使用内存缓存实体对象, 因此, 即便内存缓存实体对象当前的存储容量可以 容纳刚刚接收到的网络数据, 但是在存入网络数据后, 内存缓存实体对象的使用率已 经超过预设比例 (例如: 80%), 此时, 也需要根据预设规则 (例如: 淘汰内存缓存实 体对象中近期未使用的老化数据) 将近期未使用的老化数据存入文件缓存实体对象或 者数据库缓存实体对象中。 在经过上述缓存处理过后, 如果下次再访问该网络页面, 需要展示相同的字符串 数据时, 则无需再向网络发起请求进行数据交互而是可以直接从内存缓存实体对象中 获得相应的字符串数据进行展示, 以便减少网络流量、 加快页面展示速度、 提升用户 体验。 优选地, 在步骤 S104, 将第二类型的网络数据存储至一个或多个缓存实体对象中 之前, 还可以包括以下步骤: 步骤 S4: 获取第二类型的网络数据的大小; 步骤 S5:判断第二类型的网络数据的大小是否小于或等于第一缓存实体对象中的 剩余存储空间的大小; 步骤 S6: 如果否, 则按照预设规则将第一缓存实体对象中当前存储的部分或全部 数据进行删除, 或者, 将第一缓存实体对象中存储的部分或全部数据转移至除第一缓 存实体对象之外的其他缓存实体对象中, 其中, 上述预设规则可以包括但不限于以下 之一: 最近最少使用 LRU规则、 在缓存实体对象中存储的时间。 在优选实施例中, 当从网络侧设备接收到网络数据 (例如: 图片数据) 时, 经过 判断发现此种类型的网络数据需要进行序列化处理, 首先, 需要实现该数据类型的序 列化处理, 以此才可以作为 VALUE值来进行存储。 在完成上述序列化准备工作之后, 就可以使用缓存管理组件进行缓存。 其次, 需要从缓存实体对象集合中为网络数据选 取一个或多个缓存实体对象, 同时可以指定每个缓存实体对象的最大容量限制。 此处 的缓存实体对象可以是已经配置完成的内存缓存实体对象、 文件缓存实体对象或者数 据库缓存实体对象, 当然也可以是用户自定义的扩展缓存实体对象。 在对网络数据进 行存储的过程中, 可以预先设定存储策略(例如: 缓存实体对象的优先级), 在该优选 实施例中, 可以设定内存缓存实体对象的优先级最高、 文件缓存实体对象的优先级次 之、 数据库缓存实体对象的优先级排在最后。 然后, 开始判断优先级最高的内存缓存 实体对象当前的存储容量是否满足刚刚接收到的网络数据, 如果可以满足则直接将接 收到的网络数据存储至内存缓存实体对象中。 而如果内存缓存实体对象当前的存储容 量无法容纳刚刚接收到的网络数据, 此时, 可以根据预设规则 (例如: 淘汰内存缓存 实体对象中近期未使用的老化数据) 将近期未使用的老化数据存入文件缓存实体对象 或者数据库缓存实体对象中, 而将刚接收到的网络数据存入内存缓存实体对象, 从而 能够灵活地进行数据缓存处理, 以便不影响应用的性能和体验。 当然, 为了不影响终 端侧设备的处理能力, 避免过度使用内存缓存实体对象, 因此, 即便内存缓存实体对 象当前的存储容量可以容纳刚刚接收到的网络数据, 但是在存入网络数据后, 内存缓 存实体对象的使用率已经超过预设比例(例如: 80%),此时,也需要根据预设规则(例 如: 淘汰内存缓存实体对象中近期未使用的老化数据) 将近期未使用的老化数据存入 文件缓存实体对象或者数据库缓存实体对象中。 在经过上述缓存处理过后, 如果下次再访问该网络页面, 需要展示相同的图片数 据时, 则无需再向网络发起请求进行数据交互而是可以直接从内存缓存实体对象中获 得相应的图片数据进行展示, 以便减少网络流量、加快页面展示速度、提升用户体验。 优选地,在步骤 S104,将第一类型的网络数据存储至一个或多个缓存实体对象中, 或者, 将第二类型的网络数据存储至一个或多个缓存实体对象中之前, 还可以包括以 下处理: 步骤 S7: 为第一类型的网络数据或者第二类型的网络数据设置存储标识, 其中, 存储标识用于在将第一类型的网络数据或者第二类型的网络数据存储至一个或多个缓 存实体对象中之后查找第一类型的网络数据或者第二类型的网络数据。 在优选实施例中, 可以为每次接收到的网络数据设置存储标识 KEY, 而将网络数 据作为 VALUE, 建立 KEY与 VALUE之间的对应关系, 存储至一个或多个缓存实体 对象中, 由此可以便于后续通过 KEY对已经存储的网络数据进行查找。后续如果需要 查找哪次接收到的网络数据,可以在已知 KEY的情况下,可以直接使用获取缓存数据 功能, 通过 KEY值查找到对应数据。 如果不知道 KEY, 则可以通过缓存管理类的获 取 KEY集合功能, 遍历找到所有的 KEY, 然后找到所需 KEY值后便可以进行查询。 优选地,在步骤 S104中,将第一类型的网络数据存储至一个或多个缓存实体对象 中, 或者, 将第二类型的网络数据存储至一个或多个缓存实体对象中可以包括以下操 作- 步骤 S8: 判断一个或多个缓存实体对象中是否已经存在存储标识; 步骤 S9: 如果存在, 则直接采用第一类型的网络数据或者第二类型的网络数据对 在一个或多个缓存实体对象中当前存储的与存储标识对应的数据进行覆盖, 或者在对 与存储标识对应的数据进行回调处理后, 再采用第一类型的网络数据或者第二类型的 网络数据对与存储标识对应的数据进行覆盖。 在优选实施例中, 根据网络数据的类型, 如果是字符串数据可以不需要进行序列 化处理, 而直接作为 VALUE值来进行存储; 如果是图片数据需要实现该数据类型的 序列化处理, 以此才可以作为 VALUE值来进行存储。 在存储过程当中, 网络数据以 存储标识 KEY加以区分。 而在存储网络数据时, 为网络数据分配的存储标识 KEY并 非是唯一的, 即缓存实体对象中很可能已经存在与为刚接收到的网络数据分配的存储 标识 KEY相同的标识。 此时, 缓存实体对象中如果存在与 KEY对应的数据, 存储过 程中则会采用新数据直接覆盖旧数据, 当然, 被覆盖的旧数据还可以通过一个回调接 口返回给用户, 具体是否需要进行回调旧数据的处理可以根据用户个人需求而设定。 优选地,在步骤 S7中, 为第一类型的网络数据或者第二类型的网络数据设置存储 标识可以包括以下步骤: 步骤 S10: 遍历一个或多个缓存实体对象中已经存在的全部存储标识; 步骤 S11 : 根据遍历结果确定为第一类型的网络数据或者第二类型的网络数据设 置的存储标识, 其中, 设置的存储标识与已经存在的全部存储标识均不相同。 在优选实施例中, 为了避免增加在一个或多个缓存实体对象中查找网络数据的复 杂性与繁琐性, 同时还为了避免因存储标识相同而覆盖数据所造成的误操作引起数据 丢失, 因此, 在设置存储标识之前可以首先遍历各个缓存实体对象中已经存在哪些存 储标识, 然后再设置一个与当前已经存在的全部存储标识均不相同的存储标识。 作为本发明的一个优选实施例,在使用 android平台缓存工具进行缓存时的处理流 程可以包括以下处理步骤: 第一步、 序列化缓存数据类型, 实现 Externalizable接口; 第二步、 实例化缓存管理类, 指定缓存策略, 即内存、 文件或者是数据库, 同时 还可以选择性的指定缓存最大限制; 第三步、 指定存储标识 KEY和序列化的数据, 使用缓存管理类对应的缓存功能; 第四步、 判断 KEY和 VALUE的合法性, 必须均不为空; 第五步、 计算待存储数据的大小, 确保其小于或等于缓存最大限制; 第六步、 判断缓存中标识 KEY是否已经存在, 如果存在, 新生成的 VALUE值将 会覆盖原始值进行存储, 根据指定的缓存策略判断是否有足够的存入空间来存储待缓 存的数据, 如果没有, 则需要首先删除老化数据; 在该优选实施例中,老化数据的判断方式如下:在内存缓存机制中 LinkedHashMap 可以按照时间顺序进行存储, 因此, 排在最前面的即为已经老化的数据。 在文件缓存 机制中, 数据库除了保存有 KEY文件名, 还有对应文件的创建时间, 由此可以根据该 时间进行判断。 数据库缓存机制与文件缓存相类似, 在数据存储时会存储一个时间字 段, 查询该时间字段就可以获知老化数据。 第七步、 向缓存中写入该 K-V值, 在内存缓存机制中已经构建了依照访问顺序排 列的 LinkedHashMap, 存入数据即是增加一条映射条目; 文件缓存机制可以利用数据 库保存文件缓存相关信息,在有数据需要存入时,首先根据 KEY生成一个对应的文件 名, 然后向该文件中写入数据; 同时更新数据库, 数据库缓存机制即为向数据库中新 增一个条目; 第八步、 如果是 KEY已经存在的数据缓存, 则会通过回调, 返回 K-V旧值; 在使用上述 android平台缓存工具获取数据时, 如果在已知 KEY的情况下, 可以 直接使用获取缓存数据功能, 通过 KEY值查找到对应数据。 如果不知道 KEY, 则可 以通过缓存管理类的获取 KEY集合功能, 遍历找到所有的 KEY, 然后找到所需 KEY 值后便可以进行查询。 图 3是根据本发明实施例的数据的存储装置的结构框图。 如图 3所示, 该数据的 存储装置可以包括: 第一获取模块 100, 设置为向网络侧设备发起请求消息, 获取待 缓存的网络数据; 存储模块 102, 设置为从缓存实体对象集合中为网络数据选取一个 或多个缓存实体对象, 并直接将获取到的第一类型的网络数据存储至一个或多个缓存 实体对象中, 或者, 将经过序列化处理后的第二类型的网络数据存储至一个或多个缓 存实体对象中。 采用如图 3所示的装置, 解决了相关技术中所提供的数据缓存解决方案过分地依 赖远程网络服务, 同时还需大量地耗费网络流量以及移动终端电量的问题, 进而可以 减少对网络的依赖, 节省网络流量和移动终端的电量。 优选地, 如图 4所示, 上述装置还可以包括: 第二获取模块 104, 设置为获取第 一类型的网络数据的大小; 第一判断模块 106, 设置为判断第一类型的网络数据的大 小是否小于或等于第一缓存实体对象中的剩余存储空间的大小, 其中, 第一缓存实体 对象在一个或多个缓存实体对象中的存储优先级别最高; 第一处理模块 108, 设置为 在第一判断模块输出为否时, 按照预设规则将第一缓存实体对象中当前存储的部分或 全部数据进行删除, 或者, 将第一缓存实体对象中存储的部分或全部数据转移至除第 一缓存实体对象之外的其他缓存实体对象中, 其中, 上述预设规则可以包括但不限于 以下之一: LRU规则、 在缓存实体对象中存储的时间。 优选地, 如图 4所示, 上述装置还可以包括: 第三获取模块 110, 设置为获取第 二类型的网络数据的大小; 第二判断模块 112, 设置为判断第二类型的网络数据的大 小是否小于或等于第一缓存实体对象中的剩余存储空间的大小; 第二处理模块 114, 设置为在第二判断模块输出为否时, 按照预设规则将第一缓存实体对象中当前存储的 部分或全部数据进行删除, 或者, 将第一缓存实体对象中存储的部分或全部数据转移 至除第一缓存实体对象之外的其他缓存实体对象中, 其中, 上述预设规则可以包括但 不限于以下之一: LRU规则、 在缓存实体对象中存储的时间。 优选地, 如图 4所示, 上述装置还可以包括: 设置模块 116, 设置为为第一类型 的网络数据或者第二类型的网络数据设置存储标识, 其中, 存储标识用于在将第一类 型的网络数据或者第二类型的网络数据存储至一个或多个缓存实体对象中之后查找第 一类型的网络数据或者第二类型的网络数据。 优选地, 存储模块 102可以包括: 判断单元(图中未示出), 设置为判断一个或多 个缓存实体对象中是否已经存在存储标识; 处理单元(图中未示出), 设置为在判断单 元输出为是时, 则直接采用第一类型的网络数据或者第二类型的网络数据对在一个或 多个缓存实体对象中当前存储的与存储标识对应的数据进行覆盖, 或者在对与存储标 识对应的数据进行回调处理后, 再采用第一类型的网络数据或者第二类型的网络数据 对与存储标识对应的数据进行覆盖。 优选地, 设置模块 116可以包括: 遍历单元(图中未示出), 设置为遍历一个或多 个缓存实体对象中已经存在的全部存储标识; 确定单元(图中未示出), 设置为根据遍 历结果确定为第一类型的网络数据或者第二类型的网络数据设置的存储标识, 其中, 设置的存储标识与已经存在的全部存储标识均不相同。 从以上的描述中, 可以看出, 上述实施例实现了如下技术效果 (需要说明的是这 些效果是某些优选实施例可以达到的效果): 采用本发明所提供的技术方案, 实现在本 地的网络数据缓存, 当本地应用程序频繁地请求网络数据以及对各种资源的需求较多 时, 可以通过利用该缓存组件, 大大提高移动终端的处理性能, 同时还能够减少对网 络发起的请求。 本发明在构建了内存、 文件和数据库三种基本的缓存类别的基础上, 还预留了对其他缓存制度的扩展使用, 支持对网络图形的缓存, 备份内容无限制、 可 以备份任意数据、 文件、 图片等从网络下载的信息。 显然, 本领域的技术人员应该明白, 上述的本发明的各模块或各步骤可以用通用 的计算装置来实现, 它们可以集中在单个的计算装置上, 或者分布在多个计算装置所 组成的网络上, 可选地, 它们可以用计算装置可执行的程序代码来实现, 从而, 可以 将它们存储在存储装置中由计算装置来执行, 并且在某些情况下, 可以以不同于此处 的顺序执行所示出或描述的步骤, 或者将它们分别制作成各个集成电路模块, 或者将 它们中的多个模块或步骤制作成单个集成电路模块来实现。 这样, 本发明不限制于任 何特定的硬件和软件结合。 以上所述仅为本发明的优选实施例而已, 并不用于限制本发明, 对于本领域的技 术人员来说, 本发明可以有各种更改和变化。 凡在本发明的精神和原则之内, 所作的 任何修改、 等同替换、 改进等, 均应包含在本发明的保护范围之内。

Claims

权 利 要 求 书
1. 一种数据的存储方法, 包括:
向网络侧设备发起请求消息, 获取待缓存的网络数据;
从缓存实体对象集合中为所述网络数据选取一个或多个缓存实体对象, 并 直接将获取到的第一类型的网络数据存储至所述一个或多个缓存实体对象中, 或者, 将经过所述序列化处理后的第二类型的网络数据存储至所述一个或多个 缓存实体对象中。
2. 根据权利要求 1所述的方法, 其中, 在将所述第一类型的网络数据存储至所述 一个或多个缓存实体对象中之前, 还包括:
获取所述第一类型的网络数据的大小;
判断所述第一类型的网络数据的大小是否小于或等于第一缓存实体对象中 的剩余存储空间的大小, 其中, 所述第一缓存实体对象在所述一个或多个缓存 实体对象中的存储优先级别最高;
如果否, 则按照预设规则将所述第一缓存实体对象中当前存储的部分或全 部数据进行删除, 或者, 将所述第一缓存实体对象中存储的所述部分或全部数 据转移至除所述第一缓存实体对象之外的其他缓存实体对象中, 其中, 所述预 设规则包括以下之一:最近最少使用 LRU规则、在所述缓存实体对象中存储的 时间。
3. 根据权利要求 1所述的方法, 其中, 在将所述第二类型的网络数据存储至所述 一个或多个缓存实体对象中之前, 还包括:
获取所述第二类型的网络数据的大小;
判断所述第二类型的网络数据的大小是否小于或等于第一缓存实体对象中 的剩余存储空间的大小;
如果否, 则按照预设规则将所述第一缓存实体对象中当前存储的部分或全 部数据进行删除, 或者, 将所述第一缓存实体对象中存储的所述部分或全部数 据转移至除所述第一缓存实体对象之外的其他缓存实体对象中, 其中, 所述预 设规则包括以下之一: LRU规则、 在所述缓存实体对象中存储的时间。
4. 根据权利要求 1所述的方法, 其中, 在将所述第一类型的网络数据存储至所述 一个或多个缓存实体对象中, 或者, 将所述第二类型的网络数据存储至所述一 个或多个缓存实体对象中之前, 还包括:
为所述第一类型的网络数据或者所述第二类型的网络数据设置存储标识, 其中, 所述存储标识用于在将所述第一类型的网络数据或者所述第二类型的网 络数据存储至所述一个或多个缓存实体对象中之后查找所述第一类型的网络数 据或者所述第二类型的网络数据。
5. 根据权利要求 4所述的方法, 其中, 将所述第一类型的网络数据存储至所述一 个或多个缓存实体对象中, 或者, 将所述第二类型的网络数据存储至所述一个 或多个缓存实体对象中包括:
判断所述一个或多个缓存实体对象中是否已经存在所述存储标识; 如果存在, 则直接采用所述第一类型的网络数据或者所述第二类型的网络 数据对在所述一个或多个缓存实体对象中当前存储的与所述存储标识对应的数 据进行覆盖, 或者在对与所述存储标识对应的数据进行回调处理后, 再采用所 述第一类型的网络数据或者所述第二类型的网络数据对与所述存储标识对应的 数据进行覆盖。
6. 根据权利要求 4所述的方法, 其中, 为所述第一类型的网络数据或者所述第二 类型的网络数据设置所述存储标识包括: 遍历所述一个或多个缓存实体对象中已经存在的全部存储标识; 根据遍历结果确定为所述第一类型的网络数据或者所述第二类型的网络数 据设置的存储标识, 其中, 所述设置的存储标识与所述已经存在的全部存储标 识均不相同。
7. 根据权利要求 1至 6中任一项所述的方法, 其中, 所述缓存实体对象集合包括 以下至少之一:
初始配置的内存缓存实体对象;
初始配置的文件缓存实体对象;
初始配置的数据库缓存实体对象;
用户自定义的扩展缓存实体对象。
8. 一种数据的存储装置, 包括:
第一获取模块, 设置为向网络侧设备发起请求消息, 获取待缓存的网络数 据;
存储模块, 设置为从缓存实体对象集合中为所述网络数据选取一个或多个 缓存实体对象, 并直接将获取到的第一类型的网络数据存储至所述一个或多个 缓存实体对象中, 或者, 将经过所述序列化处理后的第二类型的网络数据存储 至所述一个或多个缓存实体对象中。
9. 根据权利要求 8所述的装置, 其中, 所述装置还包括:
第二获取模块, 设置为获取所述第一类型的网络数据的大小; 第一判断模块, 设置为判断所述第一类型的网络数据的大小是否小于或等 于第一缓存实体对象中的剩余存储空间的大小, 其中, 所述第一缓存实体对象 在所述一个或多个缓存实体对象中的存储优先级别最高;
第一处理模块, 设置为在所述第一判断模块输出为否时, 按照预设规则将 所述第一缓存实体对象中当前存储的部分或全部数据进行删除, 或者, 将所述 第一缓存实体对象中存储的所述部分或全部数据转移至除所述第一缓存实体对 象之外的其他缓存实体对象中, 其中, 所述预设规则包括以下之一: 最近最少 使用 LRU规则、 在所述缓存实体对象中存储的时间。
10. 根据权利要求 8所述的装置, 其中, 所述装置还包括:
第三获取模块, 设置为获取所述第二类型的网络数据的大小; 第二判断模块, 设置为判断所述第二类型的网络数据的大小是否小于或等 于第一缓存实体对象中的剩余存储空间的大小;
第二处理模块, 设置为在所述第二判断模块输出为否时, 按照预设规则将 所述第一缓存实体对象中当前存储的部分或全部数据进行删除, 或者, 将所述 第一缓存实体对象中存储的所述部分或全部数据转移至除所述第一缓存实体对 象之外的其他缓存实体对象中, 其中, 所述预设规则包括以下之一: 最近最少 使用 LRU规则、 在所述缓存实体对象中存储的时间。
11. 根据权利要求 8所述的装置, 其中, 所述装置还包括: 设置模块, 设置为为所述第一类型的网络数据或者所述第二类型的网络数 据设置存储标识, 其中, 所述存储标识用于在将所述第一类型的网络数据或者 所述第二类型的网络数据存储至所述一个或多个缓存实体对象中之后查找所述 第一类型的网络数据或者所述第二类型的网络数据。
12. 根据权利要求 11所述的装置, 其中, 所述存储模块包括:
判断单元, 设置为判断所述一个或多个缓存实体对象中是否已经存在所述 存储标识;
处理单元, 设置为在所述判断单元输出为是时, 则直接采用所述第一类型 的网络数据或者所述第二类型的网络数据对在所述一个或多个缓存实体对象中 当前存储的与所述存储标识对应的数据进行覆盖, 或者在对与所述存储标识对 应的数据进行回调处理后, 再采用所述第一类型的网络数据或者所述第二类型 的网络数据对与所述存储标识对应的数据进行覆盖。
13. 根据权利要求 11所述的装置, 其中, 所述设置模块包括:
遍历单元, 设置为遍历所述一个或多个缓存实体对象中已经存在的全部存 储标识;
确定单元, 设置为根据遍历结果确定为所述第一类型的网络数据或者所述 第二类型的网络数据设置的存储标识, 其中, 所述设置的存储标识与所述已经 存在的全部存储标识均不相同。
PCT/CN2013/082003 2013-07-24 2013-08-21 数据的存储方法及装置 WO2014161261A1 (zh)

Priority Applications (2)

Application Number Priority Date Filing Date Title
EP13881423.1A EP3026573A4 (en) 2013-07-24 2013-08-21 METHOD AND APPARATUS FOR STORING DATA
US14/907,199 US20160191652A1 (en) 2013-07-24 2013-08-21 Data storage method and apparatus

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201310315361.0A CN104346345B (zh) 2013-07-24 2013-07-24 数据的存储方法及装置
CN201310315361.0 2013-07-24

Publications (1)

Publication Number Publication Date
WO2014161261A1 true WO2014161261A1 (zh) 2014-10-09

Family

ID=51657459

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2013/082003 WO2014161261A1 (zh) 2013-07-24 2013-08-21 数据的存储方法及装置

Country Status (4)

Country Link
US (1) US20160191652A1 (zh)
EP (1) EP3026573A4 (zh)
CN (1) CN104346345B (zh)
WO (1) WO2014161261A1 (zh)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107704473A (zh) * 2016-08-09 2018-02-16 中国移动通信集团四川有限公司 一种数据处理方法和装置

Families Citing this family (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106681995B (zh) * 2015-11-05 2020-08-18 菜鸟智能物流控股有限公司 数据缓存方法、数据查询方法及装置
CN106055706B (zh) * 2016-06-23 2019-08-06 杭州迪普科技股份有限公司 一种缓存资源存储方法及装置
CN106341447A (zh) * 2016-08-12 2017-01-18 中国南方电网有限责任公司 基于移动终端的数据库业务智能交换方法
CN108664597A (zh) * 2018-05-08 2018-10-16 深圳市创梦天地科技有限公司 一种移动操作系统上的数据缓存装置、方法及存储介质
CN112118283B (zh) * 2020-07-30 2023-04-18 爱普(福建)科技有限公司 一种基于多级缓存的数据处理方法及系统
WO2024026592A1 (zh) * 2022-07-30 2024-02-08 华为技术有限公司 一种数据存储方法及相关装置
CN115878505B (zh) * 2023-03-01 2023-05-12 中诚华隆计算机技术有限公司 一种基于芯片实现的数据缓存方法及系统
CN117292550B (zh) * 2023-11-24 2024-02-13 天津市普迅电力信息技术有限公司 一种面向车联网应用的限速预警功能检测方法

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1615041A (zh) * 2004-08-10 2005-05-11 谢成火 一种为移动终端提供存储空间方法
CN1774697A (zh) * 2003-04-29 2006-05-17 国际商业机器公司 管理对计算环境对象的访问
CN102306166A (zh) * 2011-08-22 2012-01-04 河南理工大学 一种移动地理信息空间索引方法
CN102332030A (zh) * 2011-10-17 2012-01-25 中国科学院计算技术研究所 用于分布式键-值存储系统的数据存储、管理和查询方法及系统

Family Cites Families (11)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6249844B1 (en) * 1998-11-13 2001-06-19 International Business Machines Corporation Identifying, processing and caching object fragments in a web environment
US6233606B1 (en) * 1998-12-01 2001-05-15 Microsoft Corporation Automatic cache synchronization
US6757708B1 (en) * 2000-03-03 2004-06-29 International Business Machines Corporation Caching dynamic content
CN100458776C (zh) * 2005-01-13 2009-02-04 龙搜(北京)科技有限公司 网络缓存管理的系统和方法
EP1770954A1 (en) * 2005-10-03 2007-04-04 Amadeus S.A.S. System and method to maintain coherence of cache contents in a multi-tier software system aimed at interfacing large databases
US8621075B2 (en) * 2011-04-27 2013-12-31 Seven Metworks, Inc. Detecting and preserving state for satisfying application requests in a distributed proxy and cache system
US8751542B2 (en) * 2011-06-24 2014-06-10 International Business Machines Corporation Dynamically scalable modes
JP5204333B2 (ja) * 2011-07-04 2013-06-05 本田技研工業株式会社 金属酸素電池
US20130018875A1 (en) * 2011-07-11 2013-01-17 Lexxe Pty Ltd System and method for ordering semantic sub-keys utilizing superlative adjectives
CN103034650B (zh) * 2011-09-29 2015-10-28 北京新媒传信科技有限公司 一种数据处理系统和方法
CN102521252A (zh) * 2011-11-17 2012-06-27 四川长虹电器股份有限公司 一种远程数据的访问方法

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1774697A (zh) * 2003-04-29 2006-05-17 国际商业机器公司 管理对计算环境对象的访问
CN1615041A (zh) * 2004-08-10 2005-05-11 谢成火 一种为移动终端提供存储空间方法
CN102306166A (zh) * 2011-08-22 2012-01-04 河南理工大学 一种移动地理信息空间索引方法
CN102332030A (zh) * 2011-10-17 2012-01-25 中国科学院计算技术研究所 用于分布式键-值存储系统的数据存储、管理和查询方法及系统

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
See also references of EP3026573A4 *

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107704473A (zh) * 2016-08-09 2018-02-16 中国移动通信集团四川有限公司 一种数据处理方法和装置

Also Published As

Publication number Publication date
CN104346345A (zh) 2015-02-11
CN104346345B (zh) 2019-03-26
EP3026573A4 (en) 2016-07-27
US20160191652A1 (en) 2016-06-30
EP3026573A1 (en) 2016-06-01

Similar Documents

Publication Publication Date Title
WO2014161261A1 (zh) 数据的存储方法及装置
US10061852B1 (en) Transparent proxy tunnel caching for database access
CA2649369C (en) Synchronizing structured web site contents
CN104731516B (zh) 一种存取文件的方法、装置及分布式存储系统
CN108055302B (zh) 一种图片缓存处理方法、系统和服务器
US9673998B2 (en) Differential cache for representational state transfer (REST) API
WO2017092351A1 (zh) 缓存数据的更新方法及装置
US10645192B2 (en) Identifying content files in a cache using a response-based cache index
US9928178B1 (en) Memory-efficient management of computer network resources
CN110413845B (zh) 基于物联网操作系统的资源存储方法及装置
CN108540510B (zh) 一种云主机创建方法、装置及云服务系统
US20240028583A1 (en) Distributed data processing
CN111597259B (zh) 数据存储系统、方法、装置、电子设备及存储介质
CN109947718A (zh) 一种数据存储方法、存储平台及存储装置
US11683316B2 (en) Method and device for communication between microservices
CN113271359A (zh) 刷新缓存数据的方法、装置、电子设备和存储介质
US10402373B1 (en) Filesystem redirection
CN110347656B (zh) 文件存储系统中请求的管理方法和装置
WO2010031297A1 (zh) 一种wap网关提取业务的实现方法和系统
WO2017000540A1 (zh) 数据查询方法及装置
US20110185134A1 (en) Temporary state service protocol
CN113051244B (zh) 数据访问方法和装置、数据获取方法和装置
US8364655B2 (en) Hybrid off-peak and just-in-time integration
US9219706B2 (en) Just-in-time wrapper synchronization
CN113342837B (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: 13881423

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

WWE Wipo information: entry into national phase

Ref document number: 14907199

Country of ref document: US

Ref document number: 2013881423

Country of ref document: EP