Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7799603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T00:21:53+00:00 2026-06-02T00:21:53+00:00

APC lets you store data inside keys, but you cannot group these keys. So

  • 0

APC lets you store data inside keys, but you cannot group these keys.

So if i want to have a group called “articles”, and inside this group I would have keys that take the form of the article ID I can’t do this easily.

articles -> 5   -> cached data
         -> 10  -> cached data
         -> 17  -> cached data

         ...

I could prefix the key with the “group” name like:

article_5   -> cached data
article_10  -> cached data
article_17  -> cached data

 ...

But this it makes it impossible to delete the entire group if I want to 🙁

A working solution would be to store multidimensional arrays (this is what I’m doing now), but I don’t think it’s good because when I want to access / or delete cached data, I need to get the entire group first. So if the group has one zillion articles in it you can image what kind of array I will be iterating and searching

Do you have better ideas on how could I achieve the group thing?


edit: found another solution, not sure if it’s much better because I don’t know how reliable is yet. I’m adding a special key called __paths which is basically a multidimensional array containing the full prefixed key paths for all the other entries in the cache. And when I request or delete the cache I use this array as a reference to quickly find out the key (or group of keys) I need to remove, so I don’t have to store arrays and iterate trough all keys…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T00:21:54+00:00Added an answer on June 2, 2026 at 12:21 am

    Based upon your observations, I looked at the underlying C implementation of APC‘s caching model (apc_cache.c) to see what I could find.

    The source corroborates your observations that no grouping structure exists in the backing data store, such that any loosely-grouped collection of objects will need to be done based on some namespace constraint or a modification to the cache layer itself. I’d hoped to find some backdoor relying on key chaining by way of a linked list, but unfortunately it seems collisions are reconciled by way of a direct reallocation of the colliding slot instead of chaining.

    Further confounding this problem, APC appears to use an explicit cache model for user entries, preventing them from aging off. So, the solution Emil Vikström provided that relies on the LRU model of memcached will, unfortunately, not work.

    Without modifying the source code of APC itself, here’s what I would do:

    1. Define a namespace constraint that your entries conform to. As you’ve originally defined above, this would be something like article_ prepended to each of your entries.

    2. Define a separate list of elements in this set. Effectively, this would be the 5, 10, and 17 scheme you’d described above, but in this case, you could use some numeric type to make this more efficient than storing a whole lot of string values.

    3. Define an interface to updating this set of pointers and reconciling them with the backing memory cache, including (at minimum) the methods insert, delete, and clear. When clear is called, walk each of your pointers, reconstruct the key you used in the backing data store, and flush each from your cache.

    What I’m advocating for here is a well-defined object that performs the operations you seek efficiently. This scales linearly with the number of entries in your sub-cache, but because you’re using a numeric type for each element, you’d need over 100 million entries or so before you started to experience real memory pain at a constraint of, for example, a few hundred megabytes.


    Tamas Imrei beat me to suggesting an alternate strategy I was already in the process of documenting, but this has some major flaws I’d like to discuss.

    As defined in the backing C code, APCIterator is a linear time operation over the full data set when performing searches (using its constructor, public __construct ( string $cache [, mixed $search = null ...]] )).

    This is flatly undesirable in the case where the backing elements you’re searching for represent a small percentage of your total data, because it would walk every single element in your cache to find the ones you desire. Citing apc_cache.c:

    /* {{{ apc_cache_user_find */
    apc_cache_entry_t* apc_cache_user_find(apc_cache_t* cache, char *strkey, \
      int keylen, time_t t TSRMLS_DC)
    {
        slot_t** slot;
        ...
        slot = &cache->slots[h % cache->num_slots];
        while (*slot) {
            ...
            slot = &(*slot)->next;
        }
    }
    

    Therefore, I would most strongly recommend using an efficient, pointer-based virtual grouping solution to your problem as I’ve sketched out above. Although, in the case where you’re severely memory-restricted, the iterator approach may be most correct to conserve as much memory as possible at the expense of computation.

    Best of luck with your application.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have started to try APC to store some specific data on each webserver
Hey guys I have enabled APC on my VPS but now I can't access
Let's assume I have these variables saved in apc, memcached and eaccelerator: article_1_0 article_1_1
Lets say we have a PC used to decrypt data using the RSACryptoServiceProvider. The
I've got a PHP-fpm setup on nginx setup according to this article: http://interfacelab.com/nginx-php-fpm-apc-awesome/ PHP
I am just getting started with APC to cache data and was wondering if
Does CakePHP have support for APC, XCache and others?
I have a LAMP stack with APC installed. I have a WordPress site on
Will calling $ httpd graceful clear out the APC cache, or do I have
I use NetBeans 6.8 and have MAMP with this config on my mac: Apache

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.