Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LRU Eviction Policy #503

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions .github/workflows/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,14 @@ jobs:
run: make
- name: test
run: |
make test TESTS="--show-diff -d apc.serializer=default tests"
make test TESTS="--show-diff -d apc.serializer=php tests"
make test TESTS="--show-diff -d apc.serializer=default -d opcache.enable_cli=1 tests"
make test TESTS="--show-diff -d apc.serializer=php -d opcache.enable_cli=1 tests"
make test TESTS="--show-diff -d apc.serializer=default -d apc.eviction_policy=default tests"
make test TESTS="--show-diff -d apc.serializer=php -d apc.eviction_policy=default tests"
make test TESTS="--show-diff -d apc.serializer=default -d opcache.enable_cli=1 -d apc.eviction_policy=default tests"
make test TESTS="--show-diff -d apc.serializer=php -d opcache.enable_cli=1 -d apc.eviction_policy=default tests"
make test TESTS="--show-diff -d apc.serializer=default -d apc.eviction_policy=lru tests"
make test TESTS="--show-diff -d apc.serializer=php -d apc.eviction_policy=lru tests"
make test TESTS="--show-diff -d apc.serializer=default -d opcache.enable_cli=1 -d apc.eviction_policy=lru tests"
make test TESTS="--show-diff -d apc.serializer=php -d opcache.enable_cli=1 -d apc.eviction_policy=lru tests"
windows:
defaults:
run:
Expand Down
25 changes: 25 additions & 0 deletions apc.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,31 @@ HashTable* apc_flip_hash(HashTable *hash) {
}
/* }}} */

/*
* Eviction Policy
*/
#define APC_MAX_EVICTION_POLICIES 2

static apc_eviction_policy_t apc_eviction_policies[APC_MAX_EVICTION_POLICIES] = {
{APC_EVICTION_POLICY_LRU, "lru", (apc_sma_expunge_f) apc_cache_lru_expunge},
{APC_EVICTION_POLICY_DEFAULT, "default", (apc_sma_expunge_f) apc_cache_default_expunge}
};

/* {{{ apc_find_eviction_policy */
PHP_APCU_API apc_eviction_policy_t* apc_find_eviction_policy(const char* name) {
int i;
apc_eviction_policy_t *eviction_policy;

for(i = 0; i < APC_MAX_EVICTION_POLICIES; i++) {
eviction_policy = &apc_eviction_policies[i];
if(eviction_policy->name && (strcmp(eviction_policy->name, name) == 0)) {
return eviction_policy;
}
}
apc_warning("unknown eviction policy specified. fall back to default.");
return eviction_policy; /* default */
} /* }}} */

/*
* Serializer API
*/
Expand Down
22 changes: 22 additions & 0 deletions apc.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,28 @@ PHP_APCU_API HashTable* apc_flip_hash(HashTable *hash);
# define APC_HOTSPOT
#endif

/*
* Eviction Policy
*/
typedef enum apc_eviction_policy_type_t {
APC_EVICTION_POLICY_LRU,
APC_EVICTION_POLICY_DEFAULT
} apc_eviction_policy_type_t;

typedef zend_bool (*apc_sma_expunge_f)(void *pointer, size_t size); /* }}} */

/* {{{ struct definition: apc_eviction_policy_t */
typedef struct apc_eviction_policy_t {
apc_eviction_policy_type_t type;
const char *name;
apc_sma_expunge_f expunge_f;
} apc_eviction_policy_t;
/* }}} */

/* {{{ apc_find_eviction_policy */
PHP_APCU_API apc_eviction_policy_t *apc_find_eviction_policy(const char* name);
/* }}} */

/*
* Serializer API
*/
Expand Down
Loading