Open Preprint Systems  3.3.0
PubObjectCache.inc.php
1 <?php
2 
18  /* @var array */
19  var $_objectCache = array();
20 
21 
22  //
23  // Public API
24  //
30  function add($object, $parent) {
31  if (is_a($object, 'Submission')) {
32  $this->_insertInternally($object, 'articles', $object->getId());
33  }
34  if (is_a($object, 'ArticleGalley')) {
35  assert(is_a($parent, 'Submission'));
36  $this->_insertInternally($object, 'galleys', $object->getId());
37  $this->_insertInternally($object, 'galleysByArticle', $object->getSubmissionId(), $object->getId());
38  }
39  }
40 
49  function markComplete($cacheId, $objectId) {
50  assert(is_array($this->_objectCache[$cacheId][$objectId]));
51  $this->_objectCache[$cacheId][$objectId]['complete'] = true;
52 
53  // Order objects in the completed cache by ID.
54  ksort($this->_objectCache[$cacheId][$objectId]);
55  }
56 
69  function get($cacheId, $id1, $id2 = null) {
70  assert($this->isCached($cacheId, $id1, $id2));
71  if (is_null($id2)) {
72  $returner = $this->_objectCache[$cacheId][$id1];
73  if (is_array($returner)) unset($returner['complete']);
74  return $returner;
75  } else {
76  return $this->_objectCache[$cacheId][$id1][$id2];
77  }
78  }
79 
89  function isCached($cacheId, $id1, $id2 = null) {
90  if (!isset($this->_objectCache[$cacheId])) return false;
91 
92  $id1 = (int)$id1;
93  if (is_null($id2)) {
94  if (!isset($this->_objectCache[$cacheId][$id1])) return false;
95  if (is_array($this->_objectCache[$cacheId][$id1])) {
96  return isset($this->_objectCache[$cacheId][$id1]['complete']);
97  } else {
98  return true;
99  }
100  } else {
101  $id2 = (int)$id2;
102  return isset($this->_objectCache[$cacheId][$id1][$id2]);
103  }
104  }
105 
106 
107  //
108  // Private helper methods
109  //
118  function _insertInternally($object, $cacheId, $id1, $id2 = null) {
119  if ($this->isCached($cacheId, $id1, $id2)) return;
120 
121  if (!isset($this->_objectCache[$cacheId])) {
122  $this->_objectCache[$cacheId] = array();
123  }
124 
125  $id1 = (int)$id1;
126  if (is_null($id2)) {
127  $this->_objectCache[$cacheId][$id1] = $object;
128  } else {
129  $id2 = (int)$id2;
130  if (!isset($this->_objectCache[$cacheId][$id1])) {
131  $this->_objectCache[$cacheId][$id1] = array();
132  }
133  $this->_objectCache[$cacheId][$id1][$id2] = $object;
134  }
135  }
136 }
137 
PubObjectCache\$_objectCache
$_objectCache
Definition: PubObjectCache.inc.php:22
PubObjectCache\isCached
isCached($cacheId, $id1, $id2=null)
Definition: PubObjectCache.inc.php:92
PubObjectCache
A cache for publication objects required during export.
Definition: PubObjectCache.inc.php:17
PubObjectCache\add
add($object, $parent)
Definition: PubObjectCache.inc.php:33
PubObjectCache\markComplete
markComplete($cacheId, $objectId)
Definition: PubObjectCache.inc.php:52
PubObjectCache\_insertInternally
_insertInternally($object, $cacheId, $id1, $id2=null)
Definition: PubObjectCache.inc.php:121