I was wondering if there is a way to delete elements from the Play cache using a regex.
I'm using play 2.2.x and I'm storing elements in the cache following this pattern:
collectionName.identifier
Is there a way to expire the caché using a regular expression to match the key, like:
collectionName.[a-zA-Z0-9]+
The reason I want to do that is because sometimes I will update elements in db matching some fields, and I can't really know which elements were updated.
If there is a way in ReactiveMongo to get the updated object identifiers, that would help me as well.
Thanks for any help.
Play's cache uses Ehcache underneath. You'll need to work with Ehcache directly.
Access the underlying Ehcache object using app.plugin[EhCachePlugin].cache (see the plugin source).
Then call the Ehcache object's getKeys method to get the list of cache entry keys.
Then match the keys yourself and remove any entries that match your regex.
By the way, it would be better if you update or remove items from the cache when you update the database.
Related
I need to create a filter on Google Analytics to include only a set of pages, for example, the view will have a filter to collect data only from
www.example.com/page1.html
www.example.com/page2.html
www.example.com/page3.html
I am trying to achieve this by using a Custom Filter to Include - > Request URI and using a Regex on the Filter Pattern.
My problem is that the Regex exceeds the 255 character limitation, even after I tried to optimice the regex to be a small as possible.
Creating more than one Include Filter does not work because this way no data would be collected, so I am wondering how could I achieve this? Thank you
This is the original regex
/es/investigacion/lace\.html|/en/research/lace\.html|/es/investigacion/lace/programa-maestrias\.html|/es/investigacion/lace/alumni/latin-american-forum-entrepreneurs\.html|/es/investigacion/lace/alumni/fondo-angel-investment\.html|/es/investigacion/lace/alumni\.html|/es/investigacion/lace/fondo-inversion\.html|/es/investigacion/lace/investigacion\.html|/es/investigacion/lace/acerca-del-centro\.html|/es/investigacion/lace/alumni/estudiantes-del-pais\.html|/en/research/investigation\.html|/en/research/about-the-center\.html|/es/investigacion/lace/alumni/mentoring\.html|/es/investigacion/lace/alumni/reatu-entrepreneur-award\.html|/en/research/lace/master-program\.html|/en/research/lace/alumni\.html|/en/research/investment-fund\.html
Edit: first try to compress the regex
/es/investigacion/lace/(programa-maestrias|alumni|investigacion|programa-maestrias|alumni/latin-american-forum-entrepreneurs|alumni/fondo-angel-investment|fondo-inversion|investigacion|acerca-del-centro|alumni/estudiantes-del-pais|alumni/mentoring|alumni/incae-entrepreneur-award)\.html|
Edit: the reason for this is because I need to create a new user profile on GA, and this new profile will have access to the information of a set of URLs only; so what occurred to me is create a new View that only captures the information of this set of URLs, and then assign the profile to this view with "Read/Analyze" permissons.
There are definitely more ways to optimise the regex. For example, since all string options end with .html, you could do something like this:
/(es/investigacion/lace|en/research/lace)\.html
by taking the .html out.
You could also take out
/es/investigacion/lace
and weave in the variable part of that using |'s, eg.
/es/investigacion/lace/(programa-maestrias|alumni|investigacion)\.html
But try a few of those optimisation techniques and you should be able to fit more in.
Our analytics database has alot of empty data stored in cachedValue. This data seems to get returned forever. I want to basically check that the required data is present in the cache, and if not, then do a new lookup.
I also want to allow testers to trigger this fresh lookup using a query string variable.
I've used reflector and noticed some Invalidate functions, but this appears to just clear cookies or remove the data from the in memory cache. It looks like I want to set the cachedGeoIpHandle.GeoResolveState = Failed, not sure how to do this yet.
I also see exactly where I could make this happen in the GeoIpManager, but I can override, extend that class.
Thanks.
I'm using memcached and c++. I want to remove all keys from server using c++ api. It would be better to remove them without list of the keys.
There is function in documentation: memcached_dump and memcached_delete. First one returns the list of keys, and the second one - removes them.
But here is the quote from the docs of first function:
memcached_dump() is used to get a list of keys found in memcached(1)
servers. Because memcached(1) does not guarentee to dump all keys you
can not assume you have fetched all keys from the server.
The first question: any ways to fetch ALL keys and the second is: how to use these functions at all. There aren't any examples in documentation.
Thanks.
Sounds like you want memcached_flush ?
An elegant way to remove the memcached keys would be the use of basic delete command.
But as we don't know which keys to delete, you ought to keep a log of the data being set in the memcached. You could dump these log along with their time-stamp in any data-store. By this procedure you would be able to delete keys with certain rules thereby providing to better control in the delete operation.
Logging keys is a useful way of managing cache data when you need to be able to delete a bunch of keys. In addition, using a prefix can provide a way of managing the cached data as a whole.
function save($key,$data,$group){
cache_log_key($group,$key);
cache_save($application_prefix.$key,$data);
}
function deleteGroup($group){
$loggedKeys = cache_get_log($group);
foreach($loggedKeys as $key){
cache_delete($application_prefix.$key);
}
cache_delete_log($group);
}
Say I request
parent/child/child/page-name
in my browser. I want to extract the parent, children as well as page name. Here are the regular expressions I am currently using. There should be no limit as to how many children there are in the url request. For the time being, the page name will always be at the end and never be omitted.
^([\w-]{1,}){1} -> Match parent (returns 'parent')
(/(?:(?!/).)*[a-z]){1,}/ -> Match children (returns /child/child/)
[\w-]{1,}(?!.*[\w-]{1,}) -> Match page name (returns 'page-name')
The more I play with this, the more I feel how clunky this solution is. This is for a small CMS I am developing in ASP Classic (:(). It is sort of like the MVC routing paths. But instead of calling controllers and functions based on the URL request. I would be travelling down the hierarchy and finding the appropriate page in the database. The database is using the nested set model and is linked by a unique page name for each child.
I have tried using the split function to split with a / delimiter however I found I was nested so many split statements together it became very unreadable.
All said, I need an efficient way to parse out the parent, children as well as page name from a string. Could someone please provide an alternative solution?
To be honest, I'm not even sure if a regular expression is the best solution to my problem.
Thank you.
You could try using:
^([\w-]+)(/.*/)([\w-]+)$
And then access the three matching groups created using Match.SubMatches. See here for more details.
EDIT
Actually, assuming that you know that [\w-] is all that is used in the names of the parts, you can use ^([\w-]+)(.*)([\w-]+)$ instead and it will handle the no-child case fine by itself as well.
Can't seem to rename an existing Verity collection in ColdFusion without deleting, recreating, and rebuilding the collection. Problem is, I have some very large collections I'd rather not have to delete and rebuild from scratch. Any one have a handy trick for this conundrum?
I don't believe that there is an easy way to rename a Verity collection. You can always use
<cfcollection action="map" ...>
to assign an alias to an existing collection, provided you do not need to re-use the original name.
For the Verity part (without considering ColdFusion), it's easy enough to detach a collection, rename it, and reattach it again:
rcadmin> indexdetach
Server Alias:YourDocserver
Index Alias:CollectionName
Index Type [(c)ollection,(t)ree,(p)arametric,(r)ecommendation]:c
Save changes? [y|n]:y
<<Return>> SUCCESS
rcadmin> collpurge
Collection alias:CollectionName
Admin Alias:AdminServer
Save changes? [y|n]:y
<<Return>> SUCCESS
rcadmin> adminsignal
Admin Alias:AdminServer
Type of signal (Shutdown=2,WSRefresh=3,RestartAllServers=4):4
Save changes? [y|n]:y
<<Return>> SUCCESS
Now you can rename the collection directory, and re-attach. (If you are unsure of any of these values, check them with collget before you take it offline).
rcadmin> collset
Admin Alias:AdminServer
Collection Alias:NewCollectionName
Modify Type (Update=0, Insert=1):1
Path:
Gateway[(o)dbc|(n)otes|(e)xchange|(d)ocumentum|(f)ilesys|(w)eb|o(t)her]:
Style Alias:
Document Access (Public=0,Secure=1,Anonymous=2):
Query Parser [(s)imple|(b)oolPlus|(f)reeText|(o)ldFreeText|O(l)dSimple|O(t)her]:
Description:
Max. Search Time(msecs):
Save changes? [y|n]:y
rcadmin> indexattach
Index Alias:NewCollectionName
Index Type [(c)ollection,(t)ree,(p)arametric,(r)ecommendation]:c
Server Alias:YourDocserver
Modify Type (Update=0, Insert=1):1
Index State (offline=0,hidden=1,online=2):2
Threads (default=3):
Save changes? [y|n]:y
<<Return>> SUCCESS
It should now show up again in the 'hierarchyview'.
You can also use the "merge" utility to copy content from one collection to another, with a new name.
Looks like this is not possible. Deleting and re-creating the collection with the desired name appears to be the only approach available.