1: <?php
2:
3: namespace webfilesframework\core\datastore;
4:
5:
6: 7: 8: 9: 10: 11: 12: 13: 14: 15:
16: abstract class MAbstractCachableDatastore extends MAbstractDatastore
17: {
18: const ONE_DAY_IN_SECONDS = 86400;
19:
20:
21: protected $cachingDatastore;
22:
23: protected $latestCachingTime;
24:
25: 26: 27: 28: 29: 30:
31: public function setCachingDatastore(MAbstractDatastore $cachingDatastore)
32: {
33:
34: if ($cachingDatastore->isReadOnly()) {
35: throw new MDatastoreException("Datastore for caching data cannot be readOnly.");
36: }
37:
38: $this->cachingDatastore = $cachingDatastore;
39: }
40:
41: public function fillCachingDatastore()
42: {
43: $datastoreTransfer = new MDatastoreTransfer($this, $this->cachingDatastore);
44: $datastoreTransfer->transfer();
45: }
46:
47: public function isDatastoreCached()
48: {
49: return isset($this->cachingDatastore);
50: }
51:
52: public function getLatestCachingTime() {
53: return $this->latestCachingTime;
54: }
55:
56: 57: 58: 59: 60: 61: 62: 63:
64: public function isCacheActual() {
65:
66: if ( !isset($this->latestCachingTime) ) {
67: return false;
68: }
69:
70: return
71: ( (time() - $this->latestCachingTime)
72: > self::ONE_DAY_IN_SECONDS );
73: }
74:
75: }