Closed (fixed)
Project:
Salsa Entity
Version:
7.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Reporter:
Created:
25 Mar 2015 at 13:55 UTC
Updated:
13 May 2015 at 14:44 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
s_leu commentedHere's a first patch.
Comment #3
berdirof current.. missing part of the sentence?
Also, "in the DB" is not necessary, might also be in memcache or so.
function reference should use ()
coding standard is " , , $id" I think.
Comment #4
devlada commentedBasically, the previous patch was dropped because of the way we use variable_set / variable_get('salsa_entity_mock_max_attendee') in salsa_event.test and salsa_entity.mock.inc. Once the object is cached, further setting of salsa_entity_mock_max_attendee has no effect on the loaded object, so the only way to overcome this I see in flushing cache in tests or to write better tests.
In any case, my patch is based on the previous one, with a few improvements (please review).
Comment #5
devlada commentedI'm not sure for which entities to enable caching (I followed patch-1), maybe a good idea may be to list all entities in the backend and to allow to users to select entities they want to cache and to set cache lifetime? In any case, there will be more work probably, please specify...
Comment #6
berdirWhen working on patches, make sure that you provide an interdiff so that it is easier to review the changes. Otherwise I have to search for the changes that you made.
I noticed you introduced a new cache bin, I guess to make invalidations easier. Makes sense. However, we should also implement resetCache() in the entity controller and support to invalidate specific entities or all of them.
And if we update an existing entity or delete it, we should then call $this->resetCache(array($id));
Reads a bit strange now, you can leave faster away.
Comment #7
berdirOnce you have resetCache() support, you should use that in the tests instead of the low level function, e.g. entity_get_controller('salsa_something')->resetCache().
And no, this does not need to be configurable, at least not in a first issue.
What would be nice however is to have support for loading all entities of a given type. We use that in a few places, for example for loading salsa groups.
To do this, you need to detect the case when $ids === FALSE. In that case, do a cache get for salsaType:ALL or something like that, which should contain a list of salsa keys, then switch out $ids with a list of those, which should result in them being loaded from the cache if present. Only do this is if caching is enabled for a given type, with the same expiration.
And before returning, if $ids was FALSE, write it into the cache if we had a cache miss before.
Comment #8
devlada commentedPlease check resetCache() implementation. There are warnings in tests that currently have no idea how to solve them.
Comment #9
devlada commentedIn relation to this, to implement this case in the query() or cacheGet() method?
If we look at EntityAPIController::load(); it seems that the parent method works approximately as you want, now when we have cacheGet() and cacheSet() methods implemented?Comment #10
berdirDo not call this directly, that's why you added resetCache(), call that instead.
You have too much array nwsting, $cache_ids is already an array.
You also need to handle the case where $ids is NULL, so the else case of that IF. In that case, you need to do a wildcard cache clear that starts with the salsa type, so that *all* ID's are invalidated.
The existing code all needs to happen inside the existing if (isset($ids)).
Comment #11
devlada commentedPlease check now, interdiff should be ok.
Comment #12
berdirComment #14
devlada commentedSubmitting full patch. As I tested, there is no failed tests, but it is evident that patch causes exceptions
addcslashes() expects parameter 1 to be string, array given Warning database.inc 984 DatabaseConnection->escapeLike()I think it's related to how we use the wildcard in cache_clear_all(), It is logical that cache_clear_all($cache_ids, 'cache_salsa_entities'); do its job without wildcard set, but in that case cached entity object is not cleared.
Please check in more details.
Comment #15
devlada commentedComment #16
berdirYou still have too many arrays here. $ids is already an array, you are creating an array of arrays.
This shoudn't need the wildcard argument?
Comment #18
devlada commented1. Done.
2. I think so, but in that case event test will fail, seems to me as cache is not cleared ... in any case it is wrong to satisfy tests in this way.
Comment #20
devlada commentedEvents test improved.
Comment #22
berdirOk, I decided go ahead and commit this. We don't have too much test coverage here, but we need to do manual testing with this anyway.
Opened #2480211: Support caching of entity_load('salsa_group') for the load all caching idea.