2 +----------------------------------------------------------------------+
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-2016 Facebook, Inc. (http://www.facebook.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
17 // Individual in-memory component of the cache.
18 // Usually normal files (web static resources).
20 #ifndef incl_HPHP_CACHE_DATA_H_
21 #define incl_HPHP_CACHE_DATA_H_
35 CacheData(const CacheData
&) = delete;
36 CacheData
& operator=(const CacheData
&) = delete;
38 // --- Creation functions: call at most one of these per instance.
40 // Create a named entry with contents of regular file at <path>.
41 bool loadFromFile(const std::string
& name
, uint64_t id
,
42 const std::string
& path
);
44 // Create a named entry without any contents.
45 void createEmpty(const std::string
& name
, uint64_t id
);
47 // Create a named directory entry.
48 void createDirectory(const std::string
& name
, uint64_t id
);
50 // Point into an existing cache file on disk. Populates name on success.
51 bool loadFromMmap(MmapFile
* mmap_file
, std::string
* name
);
53 // --- End creation functions.
55 // Push the internal data for this instance to CacheSaver for serialization.
56 bool save(CacheSaver
* cs
) const;
58 bool isRegularFile() const;
59 bool isDirectory() const;
60 bool isCompressed() const;
63 uint64_t fileSize() const;
65 // Access contents if possible. Populates all three arguments on success.
66 bool getDataPointer(const char** data
, uint64_t* datalen
,
67 bool* compressed
) const;
69 // Make a decompressed copy of the data. Only works if actually compressed.
70 // Returns false if data is not compressed, or on any other error.
71 bool getDecompressedData(std::string
* data
) const;
76 static const int kFlag_Compressed
= 0x00000001;
78 static const int kFlag_RegularFile
= 0x00010000;
79 static const int kFlag_EmptyEntry
= 0x00020000;
80 static const int kFlag_Directory
= 0x00040000;
82 uint64_t createChecksum() const;
83 bool sufficientlyCompressed(uint64_t orig_size
, uint64_t new_size
) const;
90 // It might be something we malloced, or something we got via mmap...
91 const char* file_data_
;
92 uint64_t file_data_length_
;
94 // ... hence this bool.
102 #endif // incl_HPHP_CACHE_DATA_H_