Skip to content

Commit

Permalink
#27. Add _entity_get_expiration_time() and rename its counterpart to …
Browse files Browse the repository at this point in the history
…_entity_set_expiration_time().
  • Loading branch information
signalpoint committed Oct 22, 2015
1 parent 0a9f907 commit 7bf9d6e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
23 changes: 18 additions & 5 deletions src/entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ function entity_load(entity_type, ids, options) {
// If entity caching is enabled, set its expiration time and save it
// to local storage.
if (caching_enabled) {
entity_set_expiration_time(entity);
_entity_set_expiration_time(entity);
_entity_local_storage_save(entity_type, entity_id, entity);
}

Expand Down Expand Up @@ -387,17 +387,29 @@ function entity_caching_enabled() {
/**
*
*/
function entity_set_expiration_time(entity) {
function _entity_get_expiration_time() {
try {
var expiration = null;
if (
Drupal.settings.cache.entity.enabled &&
Drupal.settings.cache.entity.expiration !== 'undefined'
) {
entity.expiration = Drupal.settings.cache.entity.expiration == 0 ?
expiration = Drupal.settings.cache.entity.expiration === 0 ?
0 : time() + Drupal.settings.cache.entity.expiration;
}
return expiration;
}
catch (error) { console.log('entity_set_expiration_time - ' + error); }
catch (error) { console.log('_entity_get_expiration_time - ' + error); }
}

/**
*
*/
function _entity_set_expiration_time(entity) {
try {
entity.expiration = _entity_get_expiration_time();
}
catch (error) { console.log('_entity_set_expiration_time - ' + error); }
}

/**
Expand Down Expand Up @@ -481,7 +493,8 @@ function _entity_index_local_storage_load(entity_type, path, options) {
function _entity_index_local_storage_save(entity_type, path, result) {
try {
var index = {
expiration: 0,
entity_type: entity_type,
expiration: _entity_get_expiration_time(),
entity_ids: []
};
for (var i = 0; i < result.length; i++) {
Expand Down
2 changes: 1 addition & 1 deletion src/services/services.entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ function entity_index(entity_type, query, options) {
if (caching_enabled) {
for (var i = 0; i < result.length; i++) {
var entity = result[i];
entity_set_expiration_time(entity);
_entity_set_expiration_time(entity);
_entity_local_storage_save(
entity_type,
result[i][entity_primary_key(entity_type)],
Expand Down

0 comments on commit 7bf9d6e

Please sign in to comment.